home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / Main.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  98KB  |  5,150 lines

  1. /*
  2. **    Main.c
  3. **
  4. **    Program main routines and event loop
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* Argument vectors offsets. */
  17.  
  18. enum    {
  19.             ARG_WINDOW,ARG_PUBSCREEN,ARG_STARTUP,ARG_PORTNAME,ARG_SETTINGS,ARG_UNIT,ARG_DEVICE,
  20.             ARG_NEW,ARG_SYNC,ARG_QUIET,ARG_BEHIND,ARG_DEBUG,ARG_LANGUAGE,ARG_PHONEBOOK,ARG_AUTODIAL,
  21.             ARG_AUTOEXIT,ARG_WINDOWTITLE,
  22.  
  23.             ARG_COUNT
  24.         };
  25.  
  26.     /* The shell argument template and the corresponding help message. */
  27.  
  28. STATIC STRPTR         ArgTemplate =    "WINDOW/K,PUBSCREEN/K,STARTUP/K,PORTNAME/K,"
  29.                                     "SETTINGS/K,UNIT/K/N,DEVICE/K,NEW/S,SYNC/S,"
  30.                                     "QUIET/S,BEHIND/S,DEBUG/S,LANGUAGE/K,PHONEBOOK/K,"
  31.                                     "AUTODIAL/S,AUTOEXIT/S,WINDOWTITLE/K";
  32.  
  33. STATIC STRPTR        ArgHelp =        "\nUsage: term [WINDOW <Name>] [PUBSCREEN <Name>] [STARTUP <File name>]\n"
  34.                                     "            [SETTINGS <File or path name>] [UNIT <Number>] [DEVICE <Name>]\n"
  35.                                     "            [NEW] [SYNC] [QUIET] [BEHIND] [LANGUAGE <Name>] [PHONEBOOK <File name>]\n"
  36.                                     "            [AUTODIAL] [AUTOEXIT] [WINDOWTITLE <Title>]\n"
  37.                                     "\n"
  38.                                     "      Window = Output window specifier\n"
  39.                                     "   PubScreen = Name of public screen to open window upon\n"
  40.                                     "     Startup = ARexx script file to run on startup\n"
  41.                                     "    Settings = Main configuration file name or path name to search for it\n"
  42.                                     "        Unit = Serial device driver unit number\n"
  43.                                     "      Device = Serial device driver name\n"
  44.                                     "         New = Spawn a new `term' process\n"
  45.                                     "        Sync = Keep links to Shell environment\n"
  46.                                     "       Quiet = Start iconified\n"
  47.                                     "      Behind = Open screen behind all other screens, don't activate the window\n"
  48.                                     "   Phonebook = Name of phonebook file to load\n"
  49.                                     "    Autodial = Dial phonebook entries which are marked for autodialing\n"
  50.                                     "    Autoexit = Exit `term' after dialing all autodial entries\n"
  51.                                     " Windowtitle = Display this text as the terminal window title\n"
  52.                                     "    Language = Language to use for the user interface\n\n";
  53.  
  54.     /* Local config path variable. */
  55.  
  56. STATIC STRPTR        ConfigPath;
  57. STATIC UBYTE        ThePath[MAX_FILENAME_LENGTH];
  58.  
  59.     /* Startup file name. */
  60.  
  61. STATIC UBYTE        StartupFile[MAX_FILENAME_LENGTH];
  62.  
  63.     /* Console output window specifier. */
  64.  
  65. STATIC UBYTE        WindowName[256];
  66.  
  67.     /* Did we hang up the line? */
  68.  
  69. STATIC BOOL            HungUp;
  70.  
  71.     /* Go on redialing? */
  72.  
  73. STATIC BOOL            KeepRedialing;
  74. STATIC BOOL            AutoDial;
  75. STATIC BOOL            AutoExit;
  76.  
  77.     /* Display the connection cost? */
  78.  
  79. STATIC BOOL            DisplayHangup;
  80. STATIC ULONG        DisplayPay;
  81.  
  82.     /* Poll OwnDevUnit.library for the device to become available again? */
  83.  
  84. STATIC BOOL            PollODU;
  85. STATIC UWORD        PollODUCount;
  86.  
  87.     /* Check the menu for items to dial? */
  88.  
  89. STATIC BOOL            CheckDialMenu;
  90.  
  91.     /* Local routines */
  92.  
  93. STATIC BOOL HandleInput(VOID);
  94. STATIC VOID ClearDialMenu(VOID);
  95. STATIC BOOL EnterItemToDialList(BOOL AddedSomething,struct MenuItem *Item);
  96. STATIC BOOL DialMenuToDialList(VOID);
  97. STATIC VOID HandleMenu(ULONG Code,ULONG Qualifier);
  98. STATIC VOID HandleIconify(VOID);
  99. STATIC VOID HandleOnlineCleanup(BOOL Hangup);
  100. STATIC VOID HandleFlowChange(VOID);
  101. STATIC VOID FullHangup(BOOL ForceIt);
  102. STATIC BOOL AskDial(struct Window *Parent);
  103. STATIC VOID GoOnline(VOID);
  104. STATIC VOID ReadyToDial(struct DataDialMsg *DialMsg);
  105. STATIC VOID HandleUpload(UBYTE Type);
  106. STATIC VOID LocalReleaseSerial(VOID);
  107. STATIC VOID HandleKeyboardInput(UBYTE Char,UWORD Code,ULONG Qualifier,STRPTR InputBuffer,LONG Len);
  108.  
  109.     /* Main():
  110.      *
  111.      *    This is our main entry point.
  112.      */
  113.  
  114. LONG
  115. Main()
  116. {
  117.     LONG Error = 0;
  118.  
  119.         /* Are we running as a child of Workbench? */
  120.  
  121.     ThisProcess = (struct Process *)FindTask(NULL);
  122.  
  123.     if(ThisProcess->pr_CLI)
  124.         WBenchMsg = NULL;
  125.     else
  126.     {
  127.         WaitPort(&ThisProcess->pr_MsgPort);
  128.  
  129.         WBenchMsg = (struct WBStartup *)GetMsg(&ThisProcess->pr_MsgPort);
  130.     }
  131.  
  132.         /* Now try to open dos.library and utility.library and
  133.          * proceed to examine the startup parameters.
  134.          */
  135.  
  136.     DOSBase        = (struct DosLibrary *)OpenLibrary("dos.library",0);
  137.     UtilityBase    = OpenLibrary("utility.library",0);
  138.  
  139.     if(DOSBase && UtilityBase)
  140.     {
  141.         struct RDArgs *ArgsPtr;
  142.         STRPTR *ArgArray;
  143.         BOOL LaunchNew;
  144.  
  145.             /* Reset these first. */
  146.  
  147.         ArgsPtr        = NULL;
  148.         ArgArray    = NULL;
  149.         LaunchNew    = TRUE;
  150.  
  151.             /* We were called from Shell. */
  152.  
  153.         if(ThisProcess->pr_CLI)
  154.         {
  155.                 /* No home directory to return to. */
  156.  
  157.             WBenchLock = NULL;
  158.  
  159.                 /* Use the ReadArgs parser, allocate the
  160.                  * argument vectors...
  161.                  */
  162.  
  163.             if(ArgArray = (STRPTR *)AllocVec(sizeof(STRPTR) * (ARG_COUNT),MEMF_ANY|MEMF_CLEAR))
  164.             {
  165.                 if(ArgsPtr = (struct RDArgs *)AllocDosObject(DOS_RDARGS,TAG_DONE))
  166.                 {
  167.                     ArgsPtr->RDA_ExtHelp = ArgHelp;
  168.  
  169.                         /* Parse the args (if any). */
  170.  
  171.                     if(ReadArgs(ArgTemplate,(LONG *)ArgArray,ArgsPtr))
  172.                     {
  173.                             /* Pop a running `term' to the front? */
  174.  
  175.                         if(!ArgArray[ARG_NEW])
  176.                             LaunchNew = FALSE;
  177.  
  178.                             /* For debugging purposes; not used yet. */
  179.  
  180.                         if(ArgArray[ARG_DEBUG])
  181.                             DebugFlag = TRUE;
  182.  
  183.                             /* Special language requested? */
  184.  
  185.                         if(ArgArray[ARG_LANGUAGE])
  186.                             LimitedStrcpy(sizeof(Language),Language,ArgArray[ARG_LANGUAGE]);
  187.  
  188.                             /* Are we to use a special settings path? */
  189.  
  190.                         if(ArgArray[ARG_SETTINGS])
  191.                         {
  192.                             ConfigPath = ThePath;
  193.  
  194.                             LimitedStrcpy(sizeof(ThePath),ThePath,ArgArray[ARG_SETTINGS]);
  195.                         }
  196.  
  197.                             /* Are we to use a special ARexx host port name? */
  198.  
  199.                         if(ArgArray[ARG_PORTNAME])
  200.                             LimitedStrcpy(sizeof(RexxPortName),RexxPortName,ArgArray[ARG_PORTNAME]);
  201.  
  202.                             /* Are we to use a special output window name? */
  203.  
  204.                         if(ArgArray[ARG_WINDOW])
  205.                             LimitedStrcpy(sizeof(WindowName),WindowName,ArgArray[ARG_WINDOW]);
  206.  
  207.                             /* Are we to run an ARexx script on startup? */
  208.  
  209.                         if(ArgArray[ARG_STARTUP])
  210.                             LimitedStrcpy(sizeof(StartupFile),StartupFile,ArgArray[ARG_STARTUP]);
  211.  
  212.                             /* Load a special phonebook file */
  213.  
  214.                         if(ArgArray[ARG_PHONEBOOK])
  215.                             LimitedStrcpy(sizeof(LastPhone),LastPhone,ArgArray[ARG_PHONEBOOK]);
  216.  
  217.                         if(ArgArray[ARG_AUTODIAL])
  218.                             AutoDial = TRUE;
  219.  
  220.                         if(ArgArray[ARG_AUTOEXIT])
  221.                             AutoExit = TRUE;
  222.  
  223.                             /* Are we to open a window on a public screen? */
  224.  
  225.                         if(ArgArray[ARG_PUBSCREEN])
  226.                             LimitedStrcpy(sizeof(SomePubScreenName),SomePubScreenName,ArgArray[ARG_PUBSCREEN]);
  227.  
  228.                             /* Are we to use a special device? */
  229.  
  230.                         if(ArgArray[ARG_DEVICE])
  231.                         {
  232.                             LimitedStrcpy(sizeof(NewDevice),NewDevice,ArgArray[ARG_DEVICE]);
  233.  
  234.                             UseNewDevice = TRUE;
  235.                         }
  236.  
  237.                             /* Are we to use a special unit number? */
  238.  
  239.                         if(ArgArray[ARG_UNIT])
  240.                         {
  241.                             NewUnit = *(LONG *)ArgArray[ARG_UNIT];
  242.  
  243.                             UseNewUnit = TRUE;
  244.                         }
  245.  
  246.                             /* Are we to start up iconified? */
  247.  
  248.                         if(ArgArray[ARG_QUIET])
  249.                         {
  250.                             if(!StartupFile[0])
  251.                                 DoIconify = TRUE;
  252.                         }
  253.  
  254.                             /* Hide the screen and don't activate the window? */
  255.  
  256.                         if(ArgArray[ARG_BEHIND])
  257.                             KeepQuiet = TRUE;
  258.  
  259.                             /* Use a special window title? */
  260.  
  261.                         if(ArgArray[ARG_WINDOWTITLE])
  262.                         {
  263.                             CopyMem(ArgArray[ARG_WINDOWTITLE],WindowTitle,79);
  264.                             WindowTitle[79] = 0;
  265.                         }
  266.                         else
  267.                             WindowTitle[0] = 0;
  268.                     }
  269.                     else
  270.                         Error = IoErr();
  271.                 }
  272.                 else
  273.                     Error = IoErr();
  274.             }
  275.             else
  276.                 Error = IoErr();
  277.         }
  278.         else
  279.         {
  280.             BOOL ScrewThePath = TRUE;
  281.  
  282.                 /* Change to the program's home directory. */
  283.  
  284.             WBenchLock = CurrentDir(WBenchMsg->sm_ArgList->wa_Lock);
  285.  
  286.                 /* Open icon.library, we want to take a
  287.                  * look at the icon.
  288.                  */
  289.  
  290.             if(IconBase = OpenLibrary("icon.library",0))
  291.             {
  292.                 struct DiskObject *Icon;
  293.  
  294.                     /* Try to read the icon file. */
  295.  
  296.                 if(Icon = GetProgramIcon())
  297.                 {
  298.                     STRPTR Type;
  299.  
  300.                     if(FindToolType((UBYTE **)Icon->do_ToolTypes,"DEBUG"))
  301.                         DebugFlag = TRUE;
  302.  
  303.                     if(FindToolType((UBYTE **)Icon->do_ToolTypes,"NOPATHFIX"))
  304.                         ScrewThePath = FALSE;
  305.  
  306.                         /* Look for a `Language' tooltype. */
  307.  
  308.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"LANGUAGE"))
  309.                         LimitedStrcpy(sizeof(Language),Language,Type);
  310.  
  311.                         /* Look for a `Settings' tooltype. */
  312.  
  313.                     if(ConfigPath = FindToolType((UBYTE **)Icon->do_ToolTypes,"SETTINGS"))
  314.                     {
  315.                             /* Remember the path and continue. */
  316.  
  317.                         LimitedStrcpy(sizeof(ThePath),ThePath,ConfigPath);
  318.  
  319.                         ConfigPath = ThePath;
  320.                     }
  321.  
  322.                         /* Look for a `Phonebook' tooltype. */
  323.  
  324.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"PHONEBOOK"))
  325.                         LimitedStrcpy(sizeof(LastPhone),LastPhone,Type);
  326.  
  327.                     if(FindToolType((UBYTE **)Icon->do_ToolTypes,"AUTODIAL"))
  328.                         AutoDial = TRUE;
  329.  
  330.                     if(FindToolType((UBYTE **)Icon->do_ToolTypes,"AUTOEXIT"))
  331.                         AutoExit = TRUE;
  332.  
  333.                         /* Look for a `Portname' tooltype. */
  334.  
  335.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"PORTNAME"))
  336.                         LimitedStrcpy(sizeof(RexxPortName),RexxPortName,Type);
  337.                     else
  338.                         RexxPortName[0] = 0;
  339.  
  340.                         /* Look for a `Window' tooltype. */
  341.  
  342.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"WINDOW"))
  343.                         LimitedStrcpy(sizeof(WindowName),WindowName,Type);
  344.  
  345.                         /* Look for a `Windowtitle' tooltype. */
  346.  
  347.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"WINDOWTITLE"))
  348.                         LimitedStrcpy(sizeof(WindowTitle),WindowTitle,Type);
  349.                     else
  350.                         WindowTitle[0] = 0;
  351.  
  352.                         /* Look for a `Pubscreen' tooltype. */
  353.  
  354.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"PUBSCREEN"))
  355.                         LimitedStrcpy(sizeof(SomePubScreenName),SomePubScreenName,Type);
  356.                     else
  357.                         SomePubScreenName[0] = 0;
  358.  
  359.                         /* Look for a `Startup' tooltype. */
  360.  
  361.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"STARTUP"))
  362.                         LimitedStrcpy(sizeof(StartupFile),StartupFile,Type);
  363.                     else
  364.                         StartupFile[0] = 0;
  365.  
  366.                         /* Look for a `Device' tooltype. */
  367.  
  368.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"DEVICE"))
  369.                     {
  370.                         if(Type[0])
  371.                         {
  372.                             LimitedStrcpy(sizeof(NewDevice),NewDevice,Type);
  373.  
  374.                             UseNewDevice = TRUE;
  375.                         }
  376.                     }
  377.  
  378.                         /* Look for a `Unit' tooltype. */
  379.  
  380.                     if(Type = FindToolType((UBYTE **)Icon->do_ToolTypes,"UNIT"))
  381.                     {
  382.                         if(Type[0])
  383.                         {
  384.                             NewUnit = Atol(Type);
  385.  
  386.                             UseNewUnit = TRUE;
  387.                         }
  388.                     }
  389.  
  390.                         /* Look for a `Quiet' tooltype. */
  391.  
  392.                     if(FindToolType((UBYTE **)Icon->do_ToolTypes,"QUIET"))
  393.                     {
  394.                         if(!StartupFile[0])
  395.                             DoIconify = TRUE;
  396.                     }
  397.  
  398.                         /* Look for a `Behind' tooltype. */
  399.  
  400.                     if(FindToolType((UBYTE **)Icon->do_ToolTypes,"BEHIND"))
  401.                         KeepQuiet = TRUE;
  402.  
  403.                         /* Free the icon. */
  404.  
  405.                     FreeDiskObject(Icon);
  406.                 }
  407.  
  408.                 CloseLibrary(IconBase);
  409.                 IconBase = NULL;
  410.             }
  411.  
  412.                 /* Try to create a local CLI structure so
  413.                  * Shell commands will receive a valid
  414.                  * search path list.
  415.                  */
  416.  
  417.             if(ScrewThePath)
  418.                 AttachCLI(WBenchMsg);
  419.         }
  420.  
  421.             /* Show the error message; Error can be non-zero only if
  422.              * `term' was started from shell.
  423.              */
  424.  
  425.         if(Error)
  426.             PrintFault(Error,"term");
  427.         else
  428.         {
  429.                 /* If there is already a `term' program running, pop its window to the front. */
  430.  
  431.             if(!LaunchNew)
  432.             {
  433.                 struct TermPort *TermPort;
  434.  
  435.                     /* If no other program is running, don't bother. */
  436.  
  437.                 Forbid();
  438.  
  439.                 if(!(TermPort = TermPort = (struct TermPort *)FindPort(TERMPORTNAME)))
  440.                     LaunchNew = TRUE;
  441.                 else
  442.                 {
  443.                         /* Open intuition and pop the window to the front. */
  444.  
  445.                     if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0))
  446.                     {
  447.                         if(TermPort->TopWindow)
  448.                             BumpWindow(TermPort->TopWindow);
  449.  
  450.                         CloseLibrary((struct Library *)IntuitionBase);
  451.                         IntuitionBase = NULL;
  452.                     }
  453.                 }
  454.  
  455.                 Permit();
  456.             }
  457.  
  458.                 /* Do something sensible? */
  459.  
  460.             if(LaunchNew)
  461.             {
  462.                 BYTE OldTaskPri = ThisProcess->pr_Task.tc_Node.ln_Pri;
  463.  
  464.                 if(StackSize(NULL) < 16384)
  465.                 {
  466.                     LONG Success;
  467.  
  468.                     if(!StackCall(&Success,16384,0,(STACKCALL)HandleInput))
  469.                         Error = ERROR_NO_FREE_STORE;
  470.                 }
  471.                 else
  472.                 {
  473.                     if(!HandleInput())
  474.                         Error = ERROR_NO_FREE_STORE;
  475.                 }
  476.  
  477.                 CloseAll();
  478.  
  479.                 SetTaskPri((struct Task *)ThisProcess,OldTaskPri);
  480.             }
  481.         }
  482.  
  483.             /* Now clean up any allocated data. */
  484.  
  485.         if(ArgsPtr)
  486.         {
  487.             FreeArgs(ArgsPtr);
  488.             FreeDosObject(DOS_RDARGS,ArgsPtr);
  489.         }
  490.  
  491.         FreeVec(ArgArray);
  492.  
  493.             /* Return to the old drawer. */
  494.  
  495.         if(WBenchMsg)
  496.             CurrentDir(WBenchLock);
  497.     }
  498.  
  499.         /* Close the libraries. */
  500.  
  501.     CloseLibrary((struct Library *)DOSBase);
  502.     CloseLibrary(UtilityBase);
  503.  
  504.         /* If run from Workbench, return the startup message. */
  505.  
  506.     if(WBenchMsg)
  507.     {
  508.         Forbid();
  509.  
  510.         ReplyMsg((struct Message *)WBenchMsg);
  511.     }
  512.  
  513.     if(Error)
  514.         return(RETURN_ERROR);
  515.     else
  516.         return(RETURN_OK);
  517. }
  518.  
  519.     /* HandleInput():
  520.      *
  521.      *    This is our main input loop (check window & serial).
  522.      */
  523.  
  524. STATIC BOOL
  525. HandleInput()
  526. {
  527.     STRPTR             Result;
  528.     SENDLINE         OriginalSendLine;
  529.     PhonebookHandle    *PhoneHandle;
  530.  
  531.     ThisProcess = (struct Process *)FindTask(NULL);
  532.  
  533.         /* Open the resources we need. */
  534.  
  535.     if(Result = OpenAll(ConfigPath))
  536.     {
  537.         if(IntuitionBase && Result[0])
  538.             ShowRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  539.  
  540.         return(FALSE);
  541.     }
  542.  
  543.         /* Store the output window name. */
  544.  
  545.     if(WindowName[0])
  546.         LimitedStrcpy(sizeof(Config->MiscConfig->WindowName),Config->MiscConfig->WindowName,WindowName);
  547.  
  548.         /* Tell the user what he probably doesn't know yet. */
  549.  
  550.     if(TermVersion > Config->SerialConfig->LastVersionSaved || (TermVersion == Config->SerialConfig->LastVersionSaved && TermRevision > Config->SerialConfig->LastRevisionSaved))
  551.     {
  552.         BlockWindows();
  553.  
  554.         ScreenToFront(Window->WScreen);
  555.  
  556.         DisplayBeep(Window->WScreen);
  557.         DisplayBeep(Window->WScreen);
  558.  
  559.         ShowInfo(Window,LocaleString(MSG_ATTENTION_PLEASE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_REMINDER_TXT));
  560.  
  561.         ReleaseWindows();
  562.     }
  563.  
  564.         /* Give a hint. */
  565.  
  566.     if(Config->MiscConfig->ProtectiveMode && !FirstInvocation)
  567.     {
  568.         BlockWindows();
  569.  
  570.         if(Config->SerialConfig->BaudRate >= 4800 && Config->SerialConfig->HandshakingProtocol == HANDSHAKING_NONE && !Config->SerialConfig->DirectConnection)
  571.         {
  572.             ScreenToFront(Window->WScreen);
  573.  
  574.             if(ShowRequest(Window,LocaleString(MSG_NO_RTSCTS_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Config->SerialConfig->BaudRate))
  575.             {
  576.                 SaveConfig(Config,PrivateConfig);
  577.  
  578.                 Config->SerialConfig->HandshakingProtocol = HANDSHAKING_RTSCTS_DSR;
  579.  
  580.                 ConfigSetup();
  581.             }
  582.         }
  583.  
  584.         if(Config->SerialConfig->BaudRate >= 4800 && Config->ModemConfig->ConnectAutoBaud)
  585.         {
  586.             ScreenToFront(Window->WScreen);
  587.  
  588.             if(ShowRequest(Window,LocaleString(MSG_AUTOBAUD_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  589.             {
  590.                 SaveConfig(Config,PrivateConfig);
  591.  
  592.                 Config->ModemConfig->ConnectAutoBaud = FALSE;
  593.  
  594.                 ConfigSetup();
  595.             }
  596.         }
  597.  
  598.         ReleaseWindows();
  599.     }
  600.  
  601.         /* Don't confuse the user yet, do it later ;-) */
  602.  
  603.     FirstInvocation = FALSE;
  604.  
  605.         /* Start the online timer if a carrier is present? */
  606.  
  607.     if(Config->SerialConfig->CheckCarrier && !Config->SerialConfig->DirectConnection)
  608.     {
  609.             /* Is the carrier signal present? */
  610.  
  611.         if(!(GetSerialStatus() & CIAF_COMCD))
  612.             GoOnline();
  613.     }
  614.  
  615.         /* Start up iconified? */
  616.  
  617.     if(DoIconify)
  618.     {
  619.         HandleIconify();
  620.  
  621.         DoIconify = FALSE;
  622.     }
  623.  
  624.         /* If we came out of iconified mode, check if were told to quit. */
  625.  
  626.     if(!MainTerminated)
  627.     {
  628.         if(!KeepQuiet)
  629.             BumpWindow(Window);
  630.  
  631.             /* Set up the public screen data. */
  632.  
  633.         PubScreenStuff();
  634.  
  635.             /* Change program priority. */
  636.  
  637.         SetTaskPri((struct Task *)ThisProcess,(LONG)Config->MiscConfig->Priority);
  638.  
  639.         BlockWindows();
  640.  
  641.             /* Load the phone book. */
  642.  
  643.         if(PhoneHandle = LoadPhonebook(LastPhone))
  644.         {
  645.             DeletePhonebook(GlobalPhoneHandle);
  646.             GlobalPhoneHandle = PhoneHandle;
  647.  
  648.             strcpy(Config->PhonebookFileName,LastPhone);
  649.         }
  650.  
  651.             /* Build new menu strip. */
  652.  
  653.         if(!AttachMenu(NULL))
  654.         {
  655.             if(IntuitionBase)
  656.                 ShowRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  657.  
  658.             return(FALSE);
  659.         }
  660.         else
  661.         {
  662.             if(Online)
  663.                 SetDialMenu(FALSE);
  664.         }
  665.  
  666.             /* Show our business card. */
  667.  
  668.         if(!StartupFile[0] && !Config->CommandConfig->StartupMacro[0] && !KeepQuiet && !(GlobalPhoneHandle->AutoDial || AutoDial))
  669.             ShowAbout(TRUE);
  670.  
  671.         ReleaseWindows();
  672.  
  673.             /* Don't do anything silly. */
  674.  
  675.         KeepQuiet = FALSE;
  676.  
  677.         LogAction(LocaleString(MSG_TERMMAIN_LOGMSG_PROGRAM_STARTED_TXT),TermName,TermDate);
  678.  
  679.             /* Initialize the modem. */
  680.  
  681.         OriginalSendLine = ChangeSendLine(SendLineDial);
  682.  
  683.         SerialCommand(Config->ModemConfig->ModemInit);
  684.  
  685.             /* Execute the startup macro (if any). */
  686.  
  687.         if(Config->CommandConfig->StartupMacro[0])
  688.             SerialCommand(Config->CommandConfig->StartupMacro);
  689.  
  690.         RestoreSendLine(SendLineDial,OriginalSendLine);
  691.  
  692.             /* Check if we should dial some entries from the phonebook */
  693.             /* right upon startup */
  694.  
  695.         if(GlobalPhoneHandle->AutoDial || AutoDial)
  696.         {
  697.             PhoneEntry **Phonebook;
  698.             BOOL DidSomething;
  699.             LONG i;
  700.  
  701.             Phonebook = GlobalPhoneHandle->Phonebook;
  702.             DidSomething = FALSE;
  703.  
  704.             for(i = 0 ; i < GlobalPhoneHandle->NumPhoneEntries ; i++)
  705.             {
  706.                 if(Phonebook[i]->Header->AutoDial && GlobalPhoneHandle->Phonebook[i]->Header->Number[0])
  707.                 {
  708.                     MarkDialEntry(GlobalPhoneHandle,Phonebook[i]);
  709.  
  710.                     DidSomething = TRUE;
  711.                 }
  712.             }
  713.  
  714.             if(DidSomething)
  715.             {
  716.                 if(AddAllDialEntries(GlobalPhoneHandle))
  717.                 {
  718.                     DoDial = DIAL_LIST;
  719.  
  720.                     if(GlobalPhoneHandle->AutoExit || AutoExit)
  721.                         KeepRedialing = TRUE;
  722.                 }
  723.             }
  724.         }
  725.         else
  726.         {
  727.             PhoneEntry **Phonebook;
  728.             LONG HowMany;
  729.             LONG i;
  730.  
  731.             Phonebook = GlobalPhoneHandle->Phonebook;
  732.             HowMany = 0;
  733.  
  734.             for(i = 0 ; i < GlobalPhoneHandle->NumPhoneEntries ; i++)
  735.             {
  736.                 if(Phonebook[i]->Header->Marked > 0)
  737.                     HowMany++;
  738.             }
  739.  
  740.             if(HowMany > 0)
  741.             {
  742.                 LONG j,Counter,Which;
  743.  
  744.                 for(j = 0 ; j < HowMany ; j++)
  745.                 {
  746.                     Counter    = Which = -1;
  747.  
  748.                     for(i = 0 ; i < GlobalPhoneHandle->NumPhoneEntries ; i++)
  749.                     {
  750.                         if(Phonebook[i]->Header->Marked > 0)
  751.                         {
  752.                             if(Counter == -1 || Phonebook[i]->Header->Marked <= Counter)
  753.                             {
  754.                                 Counter    = Phonebook[i]->Header->Marked;
  755.                                 Which    = i;
  756.                             }
  757.                         }
  758.                     }
  759.  
  760.                     if(Which != -1)
  761.                     {
  762.                         MarkDialEntry(GlobalPhoneHandle,Phonebook[Which]);
  763.                         Phonebook[Which]->Header->Marked = 0;
  764.                     }
  765.                 }
  766.  
  767.                 AddAllDialEntries(GlobalPhoneHandle);
  768.             }
  769.         }
  770.  
  771.             /* Process the startup file if any. */
  772.  
  773.         if(StartupFile[0])
  774.             ActivateJob(MainJobQueue,StartupFileJob);
  775.  
  776.             /* Go into input loop... */
  777.  
  778.         do
  779.         {
  780.                 /* Dial the list */
  781.  
  782.             if(DoDial != DIAL_IGNORE)
  783.             {
  784.                 DoDial = DIAL_IGNORE;
  785.  
  786.                 if(Online && !IsListEmpty(&RexxDialMsgList))
  787.                     DispatchRexxDialMsgList(FALSE);
  788.                 else
  789.                 {
  790.                     BlockWindows();
  791.  
  792.                     ClearDialMenu();
  793.  
  794.                     do
  795.                     {
  796.                         if(!DialPanel(GlobalPhoneHandle))
  797.                         {
  798.                             KeepRedialing = FALSE;
  799.                             break;
  800.                         }
  801.                     }
  802.                     while(PhonePanel(NULL));
  803.  
  804.                     if(!GlobalPhoneHandle->AutoExit)
  805.                         KeepRedialing = FALSE;
  806.  
  807.                     SetRedialMenu();
  808.  
  809.                     ReleaseWindows();
  810.                 }
  811.             }
  812.  
  813.                 /* Process the job queue. */
  814.  
  815.             ProcessJobQueue(MainJobQueue);
  816.  
  817.                 /* Is that it? */
  818.  
  819.             if(MainTerminated)
  820.             {
  821.                 LONG Complaint;
  822.  
  823.                     /* Check if there are ARexx programs running in the background. */
  824.  
  825.                 if(GetLaunchCounter() > 0)
  826.                     Complaint = MSG_TERMMAIN_CANNOT_QUIT_YET_TXT;
  827.                 else
  828.                 {
  829.                         /* If we are about to quit, try to close the screen. */
  830.  
  831.                     if(!DeleteDisplay())
  832.                         Complaint = MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT;
  833.                     else
  834.                         Complaint = 0;
  835.                 }
  836.  
  837.                     /* Check if we must complain. */
  838.  
  839.                 if(Complaint > 0)
  840.                 {
  841.                     BlockWindows();
  842.                     ShowRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(Complaint));
  843.                     ReleaseWindows();
  844.  
  845.                     MainTerminated = FALSE;
  846.                 }
  847.             }
  848.             else
  849.             {
  850.                     /* Make the user notice not too obvious events. */
  851.  
  852.                 if(FlowInfo.Changed)
  853.                     HandleFlowChange();
  854.             }
  855.         }
  856.         while(!MainTerminated);
  857.     }
  858.  
  859.         /* Send the modem exit command. */
  860.  
  861.     SendLine = (SENDLINE)SendLineDial;
  862.     SerialCommand(Config->ModemConfig->ModemExit);
  863.  
  864.         /* Stop I/O processing. */
  865.  
  866.     ClearSerial();
  867.  
  868.         /* Say goodbye. */
  869.  
  870.     LogAction(LocaleString(MSG_TERMMAIN_LOGMSG_PROGRAM_TERMINATED_TXT));
  871.     Say(LocaleString(MSG_TERMMAIN_BYE_BYE_TXT));
  872.  
  873.     return(TRUE);
  874. }
  875.  
  876.     /* SendInputTextBuffer(STRPTR Buffer,LONG Len,BOOL Bell,BOOL ConvertLF):
  877.      *
  878.      *    Transmit text the user typed or pasted via the
  879.      *    clipboard.
  880.      */
  881.  
  882. VOID
  883. SendInputTextBuffer(STRPTR Buffer,LONG Len,BOOL Bell,BOOL ConvertLF)
  884. {
  885.     LONG Mask;
  886.     UBYTE c;
  887.  
  888.     if(Config->SerialConfig->StripBit8)
  889.         Mask = 0x7F;
  890.     else
  891.         Mask = 0xFF;
  892.  
  893.     while(Len--)
  894.     {
  895.         switch(CharType[c = (*Buffer++) & Mask])
  896.         {
  897.             case CHAR_ENTER:
  898.  
  899.                 if(Get_xOFF())
  900.                 {
  901.                     if(Bell)
  902.                         BellSignal();
  903.                 }
  904.                 else
  905.                 {
  906.                     if(ConvertLF)
  907.                     {
  908.                         switch(Config->TerminalConfig->SendCR)
  909.                         {
  910.                             case EOL_LF:
  911.  
  912.                                 SerWrite("\n",1);
  913.                                 break;
  914.  
  915.                             case EOL_CR:
  916.  
  917.                                 SerWrite("\r",1);
  918.                                 break;
  919.  
  920.                             case EOL_LFCR:
  921.  
  922.                                 SerWrite("\n\r",2);
  923.                                 break;
  924.  
  925.                             case EOL_CRLF:
  926.  
  927.                                 SerWrite("\r\n",2);
  928.                                 break;
  929.                         }
  930.                     }
  931.                     else
  932.                     {
  933.                         switch(Config->TerminalConfig->SendLF)
  934.                         {
  935.                             case EOL_LF:
  936.  
  937.                                 SerWrite("\n",1);
  938.                                 break;
  939.  
  940.                             case EOL_CR:
  941.  
  942.                                 SerWrite("\r",1);
  943.                                 break;
  944.  
  945.                             case EOL_LFCR:
  946.  
  947.                                 SerWrite("\n\r",2);
  948.                                 break;
  949.  
  950.                             case EOL_CRLF:
  951.  
  952.                                 SerWrite("\r\n",2);
  953.                                 break;
  954.                         }
  955.                     }
  956.                 }
  957.  
  958.                 break;
  959.  
  960.             case CHAR_RETURN:
  961.  
  962.                 if(Get_xOFF())
  963.                 {
  964.                     if(Bell)
  965.                         BellSignal();
  966.                 }
  967.                 else
  968.                 {
  969.                     switch(Config->TerminalConfig->SendCR)
  970.                     {
  971.                         case EOL_LF:
  972.  
  973.                             SerWrite("\n",1);
  974.                             break;
  975.  
  976.                         case EOL_CR:
  977.  
  978.                             SerWrite("\r",1);
  979.                             break;
  980.  
  981.                         case EOL_LFCR:
  982.  
  983.                             SerWrite("\n\r",2);
  984.                             break;
  985.  
  986.                         case EOL_CRLF:
  987.  
  988.                             SerWrite("\r\n",2);
  989.                             break;
  990.                     }
  991.                 }
  992.  
  993.                 break;
  994.  
  995.                 /* Restart in/output. */
  996.  
  997.             case CHAR_XON:
  998.  
  999.                 if(Config->SerialConfig->xONxOFF)
  1000.                     Clear_xOFF();
  1001.  
  1002.                 if(Config->SerialConfig->PassThrough)
  1003.                     SerWrite(&c,1);
  1004.  
  1005.                 break;
  1006.  
  1007.                 /* Stop in/output. */
  1008.  
  1009.             case CHAR_XOFF:
  1010.  
  1011.                 if(Config->SerialConfig->xONxOFF)
  1012.                     Set_xOFF();
  1013.  
  1014.                 if(Config->SerialConfig->PassThrough)
  1015.                     SerWrite(&c,1);
  1016.  
  1017.                 break;
  1018.  
  1019.                 /* Any other character. */
  1020.  
  1021.             case CHAR_VANILLA:
  1022.  
  1023.                 if(Get_xOFF())
  1024.                 {
  1025.                     if(Bell)
  1026.                         BellSignal();
  1027.                 }
  1028.                 else
  1029.                 {
  1030.                     if(Config->TerminalConfig->FontMode == FONT_IBM)
  1031.                     {
  1032.                             /* Convert special
  1033.                              * Amiga characters into
  1034.                              * alien IBM dialect.
  1035.                              */
  1036.  
  1037.                         if(IBMConversion[c])
  1038.                             SerWrite(&IBMConversion[c],1);
  1039.                         else
  1040.                             SerWrite(&c,1);
  1041.                     }
  1042.                     else
  1043.                         SerWrite(&c,1);
  1044.                 }
  1045.  
  1046.                 break;
  1047.         }
  1048.     }
  1049. }
  1050.  
  1051. STATIC VOID
  1052. ClearDialMenu()
  1053. {
  1054.     if(Menu)
  1055.     {
  1056.         struct Menu    *ThisMenu;
  1057.         struct MenuItem    *Item;
  1058.  
  1059.         ClearMenuStrips();
  1060.  
  1061.         for(ThisMenu = Menu ; ThisMenu ; ThisMenu = ThisMenu->NextMenu)
  1062.         {
  1063.             if(Item = ThisMenu->FirstItem)
  1064.             {
  1065.                 do
  1066.                 {
  1067.                     if((ULONG)GTMENUITEM_USERDATA(Item) >= DIAL_MENU_LIMIT)
  1068.                     {
  1069.                         Item->Flags &= ~CHECKED;
  1070.  
  1071.                         if(Item->SubItem)
  1072.                         {
  1073.                             struct MenuItem *SubItem = Item->SubItem;
  1074.  
  1075.                             do
  1076.                                 SubItem->Flags &= ~CHECKED;
  1077.                             while(SubItem = SubItem->NextItem);
  1078.                         }
  1079.                     }
  1080.                 }
  1081.                 while(Item = Item->NextItem);
  1082.             }
  1083.         }
  1084.  
  1085.         ResetMenuStrips(Menu);
  1086.     }
  1087. }
  1088.  
  1089. STATIC BOOL
  1090. EnterItemToDialList(BOOL AddedSomething,struct MenuItem *Item)
  1091. {
  1092.     ULONG Index;
  1093.  
  1094.     Index = (ULONG)GTMENUITEM_USERDATA(Item);
  1095.  
  1096.     if(Index >= DIAL_MENU_LIMIT && (Item->Flags & (ITEMENABLED|CHECKIT|CHECKED)) == (ITEMENABLED|CHECKIT|CHECKED))
  1097.     {
  1098.         Index -= DIAL_MENU_LIMIT;
  1099.  
  1100.         if(Index < GlobalPhoneHandle->NumPhoneEntries)
  1101.         {
  1102.                 /* Clear the checkmark. */
  1103.  
  1104.             Item->Flags &= ~CHECKED;
  1105.  
  1106.                 /* If this is the first entry to be added, clear the old dial list. */
  1107.  
  1108.             if(!AddedSomething)
  1109.                 DeleteDialList(GlobalPhoneHandle);
  1110.  
  1111.             return(AddDialEntry(GlobalPhoneHandle,GlobalPhoneHandle->Phonebook[Index],NULL));
  1112.         }
  1113.     }
  1114.  
  1115.     return(FALSE);
  1116. }
  1117.  
  1118. STATIC BOOL
  1119. DialMenuToDialList()
  1120. {
  1121.     BOOL AddedSomething = FALSE;
  1122.  
  1123.     if(Menu)
  1124.     {
  1125.         struct Menu    *ThisMenu;
  1126.         struct MenuItem    *Item;
  1127.  
  1128.         ClearMenuStrips();
  1129.  
  1130.         for(ThisMenu = Menu ; ThisMenu ; ThisMenu = ThisMenu->NextMenu)
  1131.         {
  1132.             if(Item = ThisMenu->FirstItem)
  1133.             {
  1134.                 do
  1135.                 {
  1136.                     AddedSomething |= EnterItemToDialList(AddedSomething,Item);
  1137.  
  1138.                     if(Item->SubItem)
  1139.                     {
  1140.                         struct MenuItem *SubItem = Item->SubItem;
  1141.  
  1142.                         do
  1143.                             AddedSomething |= EnterItemToDialList(AddedSomething,SubItem);
  1144.                         while(SubItem = SubItem->NextItem);
  1145.                     }
  1146.                 }
  1147.                 while(Item = Item->NextItem);
  1148.             }
  1149.         }
  1150.  
  1151.         ResetMenuStrips(Menu);
  1152.     }
  1153.  
  1154.     return(AddedSomething);
  1155. }
  1156.  
  1157.     /* HandleMenu(ULONG Code,ULONG Qualifier):
  1158.      *
  1159.      *    Skip along the number of selected menu items and
  1160.      *    handle the associated functions.
  1161.      */
  1162.  
  1163. STATIC VOID
  1164. HandleMenu(ULONG Code,ULONG Qualifier)
  1165. {
  1166.     struct MenuItem *MenuItem;
  1167.  
  1168.         /* Check until the last menuitem has been
  1169.          * processed.
  1170.          */
  1171.  
  1172.     while(Code != MENUNULL)
  1173.     {
  1174.             /* Pick up the associated menu item. */
  1175.  
  1176.         if(MenuItem = ItemAddress(Menu,Code))
  1177.         {
  1178.             HandleMenuCode((ULONG)GTMENUITEM_USERDATA(MenuItem),Qualifier);
  1179.  
  1180.             Code = MenuItem->NextSelect;
  1181.         }
  1182.         else
  1183.             break;
  1184.     }
  1185.  
  1186.         /* Enter the selected entries from the quick dial menu? */
  1187.  
  1188.     if(CheckDialMenu)
  1189.     {
  1190.         CheckDialMenu = FALSE;
  1191.  
  1192.         if(DialMenuToDialList())
  1193.             DoDial = DIAL_LIST;
  1194.     }
  1195. }
  1196.  
  1197.     /* HandleIconify():
  1198.      *
  1199.      *    Handle program iconification.
  1200.      */
  1201.  
  1202. STATIC VOID
  1203. HandleIconify()
  1204. {
  1205.     BOOL Released = FALSE;
  1206.  
  1207.         /* Set the wait mouse pointer... */
  1208.  
  1209.     BlockWindows();
  1210.  
  1211.         /* Open workbench.library. */
  1212.  
  1213.     if(WorkbenchBase)
  1214.     {
  1215.             /* Open icon.library. */
  1216.  
  1217.         if(IconBase)
  1218.         {
  1219.             UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  1220.             struct DiskObject *Icon;
  1221.  
  1222.             strcpy(LocalBuffer,Config->PathConfig->DefaultStorage);
  1223.  
  1224.             if(AddPart(LocalBuffer,"term_SleepIcon",sizeof(LocalBuffer)))
  1225.                 Icon = GetDiskObject(LocalBuffer);
  1226.             else
  1227.                 Icon = NULL;
  1228.  
  1229.             if(!Icon)
  1230.                 Icon = GetDiskObject("PROGDIR:term_SleepIcon");
  1231.  
  1232.             if(!Icon)
  1233.             {
  1234.                 if(!(Icon = GetProgramIcon()))
  1235.                     Icon = GetDefDiskObject(WBTOOL);
  1236.             }
  1237.  
  1238.                 /* Did we get an icon? */
  1239.  
  1240.             if(Icon)
  1241.             {
  1242.                 struct MsgPort *IconPort;
  1243.  
  1244.                     /* Reset the icon type. */
  1245.  
  1246.                 Icon->do_Type = NULL;
  1247.  
  1248.                     /* Default icon position. */
  1249.  
  1250.                 Icon->do_CurrentX = NO_ICON_POSITION;
  1251.                 Icon->do_CurrentY = NO_ICON_POSITION;
  1252.  
  1253.                     /* Create the Workbench reply port. */
  1254.  
  1255.                 if(IconPort = CreateMsgPort())
  1256.                 {
  1257.                     struct AppIcon *AppIcon;
  1258.  
  1259.                         /* Add the application icon. */
  1260.  
  1261.                     if(AppIcon = AddAppIconA(0,0,TermIDString,IconPort,NULL,Icon,NULL))
  1262.                     {
  1263.                         struct AppMessage *AppMessage;
  1264.  
  1265.                             /* Release the window. */
  1266.  
  1267.                         Released = TRUE;
  1268.                         ReleaseWindows();
  1269.  
  1270.                             /* Close the display. full stop. */
  1271.  
  1272.                         if(DeleteDisplay())
  1273.                         {
  1274.                             ULONG Signals;
  1275.  
  1276.                                 /* Reset and release the serial driver. */
  1277.  
  1278.                             if(Config->MiscConfig->ReleaseDevice)
  1279.                             {
  1280.                                 ClearSerial();
  1281.                                 DeleteSerial();
  1282.                             }
  1283.  
  1284.                                 /* Wait for double-click. */
  1285.  
  1286.                             IconTerminated = FALSE;
  1287.  
  1288.                             do
  1289.                             {
  1290.                                 Signals = Wait(PORTMASK(IconPort) | SIG_REXX | SIGBREAKF_CTRL_F);
  1291.  
  1292.                                     /* Received a double-click? */
  1293.  
  1294.                                 if(Signals & PORTMASK(IconPort))
  1295.                                 {
  1296.                                         /* Pick up application messages. */
  1297.  
  1298.                                     while(AppMessage = (struct AppMessage *)GetMsg(IconPort))
  1299.                                     {
  1300.                                         IconTerminated = TRUE;
  1301.  
  1302.                                         ReplyMsg((struct Message *)AppMessage);
  1303.                                     }
  1304.                                 }
  1305.  
  1306.                                     /* Wake up if ARexx command received. */
  1307.  
  1308.                                 if(Signals & SIG_REXX)
  1309.                                     while(RunJob(RexxJob));
  1310.  
  1311.                                     /* Generic wakeup signal. */
  1312.  
  1313.                                 if(Signals & SIGBREAKF_CTRL_F)
  1314.                                     IconTerminated = TRUE;
  1315.  
  1316.                                     /* Ready to leave? */
  1317.  
  1318.                                 if(IconTerminated)
  1319.                                 {
  1320.                                         /* Open the serial driver. */
  1321.  
  1322.                                     if(Config->MiscConfig->ReleaseDevice)
  1323.                                     {
  1324.                                         if(!CreateSerial(LocalBuffer,sizeof(LocalBuffer)))
  1325.                                         {
  1326.                                             switch(ShowRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_TERMMAIN_ICONIFY_IGNORE_QUIT_TXT),LocalBuffer))
  1327.                                             {
  1328.                                                 case 0:
  1329.  
  1330.                                                     MainTerminated = TRUE;
  1331.                                                     break;
  1332.  
  1333.                                                 case 1:
  1334.  
  1335.                                                     IconTerminated = FALSE;
  1336.                                                     break;
  1337.                                             }
  1338.                                         }
  1339.                                     }
  1340.                                 }
  1341.  
  1342.                                     /* Still ready to leave? */
  1343.  
  1344.                                 if(IconTerminated && !MainTerminated)
  1345.                                 {
  1346.                                     STRPTR String;
  1347.  
  1348.                                         /* Create the display. */
  1349.  
  1350.                                     if(String = CreateDisplay(TRUE,FALSE))
  1351.                                     {
  1352.                                         switch(ShowRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_TERMMAIN_ICONIFY_QUIT_TXT),String))
  1353.                                         {
  1354.                                             case 0:
  1355.  
  1356.                                                 MainTerminated = TRUE;
  1357.                                                 break;
  1358.  
  1359.                                             case 1:
  1360.  
  1361.                                                     /* Reset and release the serial driver. */
  1362.  
  1363.                                                 if(Config->MiscConfig->ReleaseDevice)
  1364.                                                 {
  1365.                                                     ClearSerial();
  1366.                                                     DeleteSerial();
  1367.                                                 }
  1368.  
  1369.                                                 IconTerminated = FALSE;
  1370.                                                 break;
  1371.                                         }
  1372.                                     }
  1373.                                     else
  1374.                                     {
  1375.                                         BumpWindow(Window);
  1376.  
  1377.                                         PubScreenStuff();
  1378.                                     }
  1379.                                 }
  1380.                             }
  1381.                             while(!IconTerminated);
  1382.                         }
  1383.                         else
  1384.                         {
  1385.                             BlockWindows();
  1386.  
  1387.                             ShowRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  1388.  
  1389.                             ReleaseWindows();
  1390.                         }
  1391.  
  1392.                             /* Remove the application icon. */
  1393.  
  1394.                         RemoveAppIcon(AppIcon);
  1395.  
  1396.                             /* Reply pending messages. */
  1397.  
  1398.                         while(AppMessage = (struct AppMessage *)GetMsg(IconPort))
  1399.                             ReplyMsg((struct Message *)AppMessage);
  1400.                     }
  1401.                     else
  1402.                         ShowRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_ADD_APPLICATION_ICON_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  1403.  
  1404.                     DeleteMsgPort(IconPort);
  1405.                 }
  1406.                 else
  1407.                     ShowRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  1408.  
  1409.                 FreeDiskObject(Icon);
  1410.             }
  1411.             else
  1412.                 ShowRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_TOOL_ICON_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  1413.         }
  1414.         else
  1415.             ShowRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_ICON_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  1416.     }
  1417.     else
  1418.         ShowRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_WORKBENCH_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  1419.  
  1420.     if(!Released)
  1421.         ReleaseWindows();
  1422.  
  1423.         /* Finished! */
  1424.  
  1425.     DoIconify = FALSE;
  1426. }
  1427.  
  1428.     /* HandleOnlineCleanup():
  1429.      *
  1430.      *    Perform offline cleanup tasks.
  1431.      */
  1432.  
  1433. STATIC VOID
  1434. HandleOnlineCleanup(BOOL Hangup)
  1435. {
  1436.     SoundPlay(SOUND_DISCONNECT);
  1437.  
  1438.         /* Execute logoff macro. */
  1439.  
  1440.     if(Config->CommandConfig->LogoffMacro[0] && WasOnline)
  1441.         SerialCommand(Config->CommandConfig->LogoffMacro);
  1442.  
  1443.     StopCall(FALSE);
  1444.  
  1445.         /* Keep the current connection costs */
  1446.  
  1447.     DisplayPay = StopAccountant();
  1448.  
  1449.     SetDialMenu(TRUE);
  1450.  
  1451.     if(!Hangup)
  1452.         Say(LocaleString(MSG_TERMAUX_CARRIER_LOST_TXT));
  1453.  
  1454.         /* Clear the password. */
  1455.  
  1456.     Password[0] = 0;
  1457.     UserName[0]    = 0;
  1458.  
  1459.     CurrentBBSName[0]        = 0;
  1460.     CurrentBBSComment[0]    = 0;
  1461.     CurrentBBSNumber[0]        = 0;
  1462.  
  1463.     if(!Config->SerialConfig->CheckCarrier || Config->SerialConfig->DirectConnection)
  1464.     {
  1465.         ObtainSemaphore(&OnlineSemaphore);
  1466.         Online = WasOnline = FALSE;
  1467.         ReleaseSemaphore(&OnlineSemaphore);
  1468.     }
  1469.  
  1470.     SetActivePattern(NULL);
  1471.     SetActiveEntry(GlobalPhoneHandle,NULL);
  1472.  
  1473.     DisarmLimit();
  1474.  
  1475.         /* Previous configuration available? */
  1476.  
  1477.     if(BackupConfig)
  1478.     {
  1479.             /* Remember old configuration. */
  1480.  
  1481.         SaveConfig(Config,PrivateConfig);
  1482.  
  1483.             /* Copy configuration. */
  1484.  
  1485.         SaveConfig(BackupConfig,Config);
  1486.  
  1487.             /* Set up new configuration. */
  1488.  
  1489.         ConfigSetup();
  1490.  
  1491.             /* Free old configuration. */
  1492.  
  1493.         DeleteConfiguration(BackupConfig);
  1494.  
  1495.         BackupConfig = NULL;
  1496.     }
  1497.  
  1498.         /* Display the connection cost next time control */
  1499.         /* passes through the main loop. */
  1500.  
  1501.     ActivateJob(MainJobQueue,DisplayCostJob);
  1502.  
  1503.     DisplayHangup = Hangup;
  1504.  
  1505.     if(Config->ModemConfig->RedialAfterHangup || KeepRedialing)
  1506.     {
  1507.         if(GlobalPhoneHandle->DialList)
  1508.         {
  1509.             if(!IsListEmpty(GlobalPhoneHandle->DialList))
  1510.             {
  1511.                 ObtainSemaphore(&OnlineSemaphore);
  1512.                 Online = WasOnline = FALSE;
  1513.                 ReleaseSemaphore(&OnlineSemaphore);
  1514.  
  1515.                 DoDial = DIAL_LIST;
  1516.             }
  1517.             else
  1518.             {
  1519.                 if(KeepRedialing)
  1520.                 {
  1521.                     KeepRedialing = FALSE;
  1522.  
  1523.                     if(GlobalPhoneHandle->AutoExit)
  1524.                         MainTerminated = TRUE;
  1525.                 }
  1526.             }
  1527.         }
  1528.         else
  1529.             KeepRedialing = FALSE;
  1530.     }
  1531. }
  1532.  
  1533.     /* HandleFlowChange():
  1534.      *
  1535.      *    Handle data flow scanner information.
  1536.      */
  1537.  
  1538. STATIC VOID
  1539. HandleFlowChange()
  1540. {
  1541.     if(Online)
  1542.     {
  1543.         if(FlowInfo.NoCarrier)
  1544.         {
  1545.             if(Config->SerialConfig->CheckCarrier && !Config->SerialConfig->DirectConnection)
  1546.             {
  1547.                     /* Is the carrier still present? */
  1548.  
  1549.                 if(!(GetSerialStatus() & CIAF_COMCD))
  1550.                     FlowInfo.NoCarrier = FALSE;
  1551.             }
  1552.  
  1553.             if(FlowInfo.NoCarrier)
  1554.                 SetOnlineState(FALSE);
  1555.         }
  1556.     }
  1557.     else
  1558.     {
  1559.         if(FlowInfo.Voice)
  1560.         {
  1561.             UBYTE DateTimeBuffer[256];
  1562.  
  1563.             FormatStamp(NULL,DateTimeBuffer,sizeof(DateTimeBuffer),FALSE);
  1564.  
  1565.             WakeUp(Window,SOUND_VOICE);
  1566.  
  1567.             ConPrintf(LocaleString(MSG_TERMMAIN_INCOMING_VOIC_CALL_TXT),DateTimeBuffer);
  1568.  
  1569.             Say(LocaleString(MSG_TERMMAIN_SAY_INCOMING_VOICE_CALL_TXT));
  1570.         }
  1571.  
  1572.         if(FlowInfo.Ring)
  1573.         {
  1574.             UBYTE DateTimeBuffer[256];
  1575.  
  1576.             FormatStamp(NULL,DateTimeBuffer,sizeof(DateTimeBuffer),FALSE);
  1577.  
  1578.             WakeUp(Window,SOUND_RING);
  1579.  
  1580.             ConPrintf(LocaleString(MSG_TERMMAIN_INCOMING_CALL_TXT),DateTimeBuffer);
  1581.  
  1582.             Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1583.         }
  1584.  
  1585.         if(FlowInfo.Connect)
  1586.         {
  1587.                 /* Are we to check the carrier signal? */
  1588.  
  1589.             if(Config->SerialConfig->CheckCarrier && !Config->SerialConfig->DirectConnection)
  1590.             {
  1591.                     /* No carrier signal present? */
  1592.  
  1593.                 if(GetSerialStatus() & CIAF_COMCD)
  1594.                     FlowInfo.Connect = FALSE;
  1595.             }
  1596.  
  1597.             if(FlowInfo.Connect)
  1598.             {
  1599.                 WakeUp(Window,SOUND_CONNECT);
  1600.  
  1601.                 SetOnlineState(TRUE);
  1602.  
  1603.                 BaudPending = FALSE;
  1604.  
  1605.                 SetDialMenu(FALSE);
  1606.             }
  1607.         }
  1608.     }
  1609.  
  1610.         /* Check if we are to prompt the user for
  1611.          * file transfer.
  1612.          */
  1613.  
  1614.     if(FlowInfo.Signature)
  1615.     {
  1616.         LONG Type = FlowInfo.Signature - SCAN_SIGDEFAULTUPLOAD + TRANSFERSIG_DEFAULTUPLOAD;
  1617.  
  1618.         BlockWindows();
  1619.  
  1620.         switch(Type)
  1621.         {
  1622.             case TRANSFERSIG_DEFAULTUPLOAD:
  1623.  
  1624.                 switch(UploadPanel(TRUE))
  1625.                 {
  1626.                     case UPLOAD_TEXT:
  1627.  
  1628. #ifdef BUILTIN_ZMODEM
  1629.                         if(UseInternalZModem)
  1630.                         {
  1631.                             InternalZModemTextUpload();
  1632.                             break;
  1633.                         }
  1634. #endif    /* BUILTIN_ZMODEM */
  1635.  
  1636.                         StartSendXPR_AskForFile(TRANSFER_TEXT,TRUE);
  1637.                         break;
  1638.  
  1639.                     case UPLOAD_BINARY:
  1640.  
  1641. #ifdef BUILTIN_ZMODEM
  1642.                         if(UseInternalZModem)
  1643.                         {
  1644.                             InternalZModemBinaryUpload();
  1645.                             break;
  1646.                         }
  1647. #endif    /* BUILTIN_ZMODEM */
  1648.  
  1649.                         StartSendXPR_AskForFile(TRANSFER_BINARY,TRUE);
  1650.                         break;
  1651.  
  1652.                     case UPLOAD_ABORT:
  1653.  
  1654.                         CancelZModem();
  1655.                         break;
  1656.  
  1657.                     case UPLOAD_BINARY_FROM_LIST:
  1658.  
  1659.                         HandleUpload(UPLOAD_BINARY);
  1660.                         break;
  1661.  
  1662.                     case UPLOAD_TEXT_FROM_LIST:
  1663.  
  1664.                         HandleUpload(UPLOAD_TEXT);
  1665.                         break;
  1666.                 }
  1667.  
  1668.                 break;
  1669.  
  1670.             case TRANSFERSIG_DEFAULTDOWNLOAD:
  1671.  
  1672. #ifdef BUILTIN_ZMODEM
  1673.                 if(UseInternalZModem)
  1674.                 {
  1675.                     ZReceive();
  1676.                     break;
  1677.                 }
  1678. #endif    /* BUILTIN_ZMODEM */
  1679.  
  1680.                 switch(UploadPanel(FALSE))
  1681.                 {
  1682.                     case UPLOAD_TEXT:
  1683.  
  1684.                         StartReceiveXPR_AskForFile(TRANSFER_TEXT,TRUE);
  1685.                         break;
  1686.  
  1687.                     case UPLOAD_BINARY:
  1688.  
  1689.                         StartReceiveXPR_AskForFile(TRANSFER_BINARY,TRUE);
  1690.                         break;
  1691.                 }
  1692.  
  1693.                 break;
  1694.  
  1695.             case TRANSFERSIG_ASCIIUPLOAD:
  1696.  
  1697.                 if(ChangeProtocol(Config->TransferConfig->ASCIIUploadLibrary,Config->TransferConfig->ASCIIUploadType))
  1698.                     StartSendXPR_AskForFile(TRANSFER_ASCII,TRUE);
  1699.  
  1700.                 ResetProtocol();
  1701.  
  1702.                 break;
  1703.  
  1704.             case TRANSFERSIG_ASCIIDOWNLOAD:
  1705.  
  1706.                 if(ChangeProtocol(Config->TransferConfig->ASCIIDownloadLibrary,Config->TransferConfig->ASCIIDownloadType))
  1707.                     StartReceiveXPR_AskForFile(TRANSFER_ASCII,TRUE);
  1708.  
  1709.                 ResetProtocol();
  1710.  
  1711.                 break;
  1712.  
  1713.             case TRANSFERSIG_TEXTUPLOAD:
  1714.  
  1715. #ifdef BUILTIN_ZMODEM
  1716.                 if(UseInternalZModem)
  1717.                 {
  1718.                     InternalZModemTextUpload();
  1719.                     break;
  1720.                 }
  1721. #endif    /* BUILTIN_ZMODEM */
  1722.  
  1723.                 if(ChangeProtocol(Config->TransferConfig->TextUploadLibrary,Config->TransferConfig->TextUploadType))
  1724.                     StartSendXPR_AskForFile(TRANSFER_TEXT,TRUE);
  1725.  
  1726.                 ResetProtocol();
  1727.  
  1728.                 break;
  1729.  
  1730.             case TRANSFERSIG_TEXTDOWNLOAD:
  1731.  
  1732. #ifdef BUILTIN_ZMODEM
  1733.                 if(UseInternalZModem)
  1734.                 {
  1735.                     ZReceive();
  1736.                     break;
  1737.                 }
  1738. #endif    /* BUILTIN_ZMODEM */
  1739.  
  1740.                 if(ChangeProtocol(Config->TransferConfig->TextDownloadLibrary,Config->TransferConfig->TextDownloadType))
  1741.                     StartReceiveXPR_AskForFile(TRANSFER_TEXT,TRUE);
  1742.  
  1743.                 ResetProtocol();
  1744.  
  1745.                 break;
  1746.  
  1747.             case TRANSFERSIG_BINARYUPLOAD:
  1748.  
  1749. #ifdef BUILTIN_ZMODEM
  1750.                 if(UseInternalZModem)
  1751.                 {
  1752.                     InternalZModemBinaryUpload();
  1753.                     break;
  1754.                 }
  1755. #endif    /* BUILTIN_ZMODEM */
  1756.  
  1757.                 if(ChangeProtocol(Config->TransferConfig->BinaryUploadLibrary,Config->TransferConfig->BinaryUploadType))
  1758.                     StartSendXPR_AskForFile(TRANSFER_BINARY,TRUE);
  1759.  
  1760.                 ResetProtocol();
  1761.  
  1762.                 break;
  1763.  
  1764.             case TRANSFERSIG_BINARYDOWNLOAD:
  1765.  
  1766. #ifdef BUILTIN_ZMODEM
  1767.                 if(UseInternalZModem)
  1768.                 {
  1769.                     ZReceive();
  1770.                     break;
  1771.                 }
  1772. #endif    /* BUILTIN_ZMODEM */
  1773.  
  1774.                 if(ChangeProtocol(Config->TransferConfig->BinaryDownloadLibrary,Config->TransferConfig->BinaryDownloadType))
  1775.                     StartReceiveXPR_AskForFile(TRANSFER_BINARY,TRUE);
  1776.  
  1777.                 ResetProtocol();
  1778.  
  1779.                 break;
  1780.         }
  1781.  
  1782.         ReleaseWindows();
  1783.     }
  1784.  
  1785.     ResetDataFlowFilter();
  1786. }
  1787.  
  1788.     /* FullHangup():
  1789.      *
  1790.      *    In a nutshell, do the full work required to hang up the line.
  1791.      */
  1792.  
  1793. STATIC VOID
  1794. FullHangup(BOOL ForceIt)
  1795. {
  1796.     BlockWindows();
  1797.  
  1798.     DispatchRexxDialMsgList(FALSE);
  1799.  
  1800.     HangUp();
  1801.  
  1802.     ReleaseWindows();
  1803.  
  1804.     if(Config->SerialConfig->CheckCarrier && !ForceIt && !Config->SerialConfig->DirectConnection)
  1805.         HungUp = TRUE;
  1806.     else
  1807.     {
  1808.         SetOnlineState(FALSE);
  1809.  
  1810.         HandleOnlineCleanup(TRUE);
  1811.     }
  1812. }
  1813.  
  1814.     /* AskDial(struct Window *Parent):
  1815.      *
  1816.      *    This is called when the user is about to start dialing. If the
  1817.      *    dial button/menu item is available with the protective mode
  1818.      *    enabled, a message will be displayed, asking if the line
  1819.      *    should be hung up before proceeding.
  1820.      */
  1821.  
  1822. STATIC BOOL
  1823. AskDial(struct Window *Parent)
  1824. {
  1825.     if(!DialItemsAvailable)
  1826.     {
  1827.         if(ShowRequest(Parent,LocaleString(MSG_CANNOT_DIAL_BECAUSE_TXT),LocaleString(MSG_DIAL_CANCEL_TXT)))
  1828.             FullHangup(TRUE);
  1829.         else
  1830.             return(FALSE);
  1831.     }
  1832.  
  1833.     return(TRUE);
  1834. }
  1835.  
  1836.     /* GoOnline():
  1837.      *
  1838.      *    Go into online state.
  1839.      */
  1840.  
  1841. STATIC VOID
  1842. GoOnline()
  1843. {
  1844.     SetOnlineState(TRUE);
  1845.  
  1846.     BaudCount        = 0;
  1847.     BaudBuffer[0]    = 0;
  1848.     BaudPending        = FALSE;
  1849.  
  1850.     Password[0]        = 0;
  1851.     UserName[0]        = 0;
  1852.  
  1853.     SendStartup        = FALSE;
  1854.  
  1855.     DisarmLimit();
  1856.  
  1857.     CurrentBBSName[0]        = 0;
  1858.     CurrentBBSComment[0]    = 0;
  1859.     CurrentBBSNumber[0]        = 0;
  1860.  
  1861.     SetActivePattern(NULL);
  1862.     SetActiveEntry(GlobalPhoneHandle,NULL);
  1863.  
  1864.     SetDialMenu(FALSE);
  1865. }
  1866.  
  1867. STATIC VOID
  1868. ReadyToDial(struct DataDialMsg *DialMsg)
  1869. {
  1870.     struct GenericDialNode *Node;
  1871.     PhoneEntry **Phonebook;
  1872.     BOOL DidSomething;
  1873.  
  1874.     DidSomething = FALSE;
  1875.  
  1876.     AddTail(&RexxDialMsgList,(struct Node *)DialMsg->DialMsg);
  1877.  
  1878.     Phonebook = GlobalPhoneHandle->Phonebook;
  1879.  
  1880.     while(Node = (struct GenericDialNode *)RemHead(DialMsg->DialList))
  1881.     {
  1882.         if(Node->Index != -1)
  1883.         {
  1884.             if(Node->Index >= 0 && Node->Index < GlobalPhoneHandle->NumPhoneEntries)
  1885.                 DidSomething |= AddDialEntry(GlobalPhoneHandle,Phonebook[Node->Index],NULL);
  1886.         }
  1887.         else
  1888.         {
  1889.             if(Node->Number != NULL)
  1890.                 DidSomething |= AddDialEntry(GlobalPhoneHandle,NULL,Node->Number);
  1891.             else
  1892.             {
  1893.                 LONG i;
  1894.  
  1895.                 for(i = 0 ; i < GlobalPhoneHandle->NumPhoneEntries ; i++)
  1896.                 {
  1897.                     if(!Stricmp(Phonebook[i]->Header->Name,Node->Node.ln_Name))
  1898.                     {
  1899.                         if(Phonebook[i]->Header->Number[0])
  1900.                             DidSomething |= AddDialEntry(GlobalPhoneHandle,Phonebook[i],NULL);
  1901.                     }
  1902.                 }
  1903.             }
  1904.         }
  1905.  
  1906.         FreeVecPooled(Node);
  1907.     }
  1908.  
  1909.     if(DidSomething)
  1910.         DoDial = DIAL_LIST;
  1911. }
  1912.  
  1913. STATIC VOID
  1914. HandleUpload(UBYTE Type)
  1915. {
  1916.     LockGenericList(GenericListTable[GLIST_UPLOAD]);
  1917.  
  1918.     if(GenericListCount(GenericListTable[GLIST_UPLOAD]) > 0)
  1919.     {
  1920.         struct FileTransferInfo *Info;
  1921.  
  1922.         if(Info = AllocFileTransferInfo())
  1923.         {
  1924.             LONG FilesFound;
  1925.             APTR OldPtr;
  1926.             struct Node *Node;
  1927.             BPTR FileLock;
  1928.             D_S(struct FileInfoBlock,FileInfo);
  1929.  
  1930.             FilesFound = 0;
  1931.  
  1932.             DisableDOSRequesters(&OldPtr);
  1933.  
  1934.             for(Node = ((struct List *)GenericListTable[GLIST_UPLOAD])->lh_Head ; Node->ln_Succ ; Node = Node->ln_Succ)
  1935.             {
  1936.                 if(FileLock = Lock(Node->ln_Name,ACCESS_READ))
  1937.                 {
  1938.                     if(Examine(FileLock,FileInfo))
  1939.                     {
  1940.                         if(FileInfo->fib_DirEntryType < 0)
  1941.                         {
  1942.                             if(AddFileTransferNode(Info,Node->ln_Name,FileInfo->fib_Size))
  1943.                                 FilesFound++;
  1944.  
  1945.                             if(Config->TransferConfig->TransferIcons)
  1946.                             {
  1947.                                 UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  1948.                                 BPTR InfoLock;
  1949.  
  1950.                                 LimitedSPrintf(sizeof(LocalBuffer),LocalBuffer,"%s.info",Node->ln_Name);
  1951.  
  1952.                                 if(InfoLock = Lock(LocalBuffer,ACCESS_READ))
  1953.                                 {
  1954.                                     if(Examine(InfoLock,FileInfo))
  1955.                                     {
  1956.                                         if(FileInfo->fib_DirEntryType < 0)
  1957.                                         {
  1958.                                             if(AddFileTransferNode(Info,LocalBuffer,FileInfo->fib_Size))
  1959.                                                 FilesFound++;
  1960.                                         }
  1961.                                     }
  1962.  
  1963.                                     UnLock(InfoLock);
  1964.                                 }
  1965.                             }
  1966.                         }
  1967.                     }
  1968.  
  1969.                     UnLock(FileLock);
  1970.                 }
  1971.             }
  1972.  
  1973.             ClearGenericList(GenericListTable[GLIST_UPLOAD],TRUE);
  1974.  
  1975.             EnableDOSRequesters(OldPtr);
  1976.  
  1977.             if(FilesFound)
  1978.             {
  1979.                 BlockWindows();
  1980.  
  1981.                 ReadyFileTransferInfo(Info,FALSE);
  1982.  
  1983.                 FileTransferInfo = Info;
  1984.  
  1985.                 StartSendXPR_FromList(Type == UPLOAD_BINARY ? TRANSFER_BINARY : TRANSFER_TEXT,TRUE);
  1986.  
  1987.                 ReleaseWindows();
  1988.             }
  1989.             else
  1990.                 FreeFileTransferInfo(Info);
  1991.         }
  1992.     }
  1993.     else
  1994.         StartSendXPR_AskForFile(Type == UPLOAD_BINARY ? TRANSFER_BINARY : TRANSFER_TEXT,TRUE);
  1995.  
  1996.     UnlockGenericList(GenericListTable[GLIST_UPLOAD]);
  1997. }
  1998.  
  1999.     /* LocalReleaseSerial():
  2000.      *
  2001.      *    Release the serial device driver, then reopen it again.
  2002.      */
  2003.  
  2004. STATIC VOID
  2005. LocalReleaseSerial()
  2006. {
  2007.     BOOL Continue,SerialClosed;
  2008.     APTR OldPtr;
  2009.  
  2010.     DB(kprintf("in: LocalReleaseSerial()\n"));
  2011.  
  2012.     ChangeWindowPtr(&OldPtr,(APTR)Window);
  2013.  
  2014.         /* This might happen if an ARexx user
  2015.          * released the serial device and
  2016.          * failed to reopen it.
  2017.          */
  2018.  
  2019.     if(ReadPort)
  2020.         SerialClosed = FALSE;
  2021.     else
  2022.         SerialClosed = TRUE;
  2023.  
  2024.     DB(kprintf("blockwindows\n"));
  2025.  
  2026.     BlockWindows();
  2027.  
  2028.         /* Prevent catastrophes! */
  2029.  
  2030.     if(!Config->MiscConfig->ProtectiveMode)
  2031.         Continue = TRUE;
  2032.     else
  2033.     {
  2034.         if(Online && !SerialClosed)
  2035.         {
  2036.             if(!ShowRequest(Window,LocaleString(MSG_TERMMAIN_YOU_ARE_STILL_ONLINE_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  2037.                 Continue = FALSE;
  2038.             else
  2039.                 Continue = TRUE;
  2040.         }
  2041.         else
  2042.             Continue = TRUE;
  2043.     }
  2044.  
  2045.     DB(kprintf("continue=%ld serialclosed=%ld\n",Continue,SerialClosed));
  2046.  
  2047.     if(Continue)
  2048.     {
  2049.         if(SerialClosed)
  2050.         {
  2051.             DB(kprintf("reopenserial\n"));
  2052.  
  2053.             ReopenSerial();
  2054.         }
  2055.         else
  2056.         {
  2057.             DB(kprintf("clearserial\n"));
  2058.             ClearSerial();
  2059.  
  2060.             DB(kprintf("deleteserial\n"));
  2061.             DeleteSerial();
  2062.  
  2063.             switch(ShowRequest(Window,LocaleString(MSG_TERMMAIN_UNIT_RESET_AND_RELEASED_TXT),LocaleString(MSG_TERMMAIN_RETURN_QUIT_TXT),Config->SerialConfig->SerialDevice,Config->SerialConfig->UnitNumber))
  2064.             {
  2065.                 case 0:
  2066.  
  2067.                     MainTerminated = TRUE;
  2068.                     break;
  2069.  
  2070.                 case 1:
  2071.  
  2072.                     ReopenSerial();
  2073.                     break;
  2074.  
  2075.                 case 2:
  2076.  
  2077.                     ActivateJob(MainJobQueue,IconifyJob);
  2078.                     break;
  2079.             }
  2080.         }
  2081.     }
  2082.  
  2083.     RestoreWindowPtr(OldPtr);
  2084.  
  2085.     ReleaseWindows();
  2086.  
  2087.     DB(kprintf("out: LocalReleaseSerial()\n"));
  2088. }
  2089.  
  2090.     /* HandleKeyboardInput():
  2091.      *
  2092.      *    Process the keyboard input.
  2093.      */
  2094.  
  2095. STATIC VOID
  2096. HandleKeyboardInput(UBYTE Char,UWORD Code,ULONG Qualifier,STRPTR InputBuffer,LONG Len)
  2097. {
  2098.         /* Take care of the numeric keypad. */
  2099.  
  2100.     if((Qualifier & IEQUALIFIER_NUMERICPAD) && (Config->EmulationConfig->NumericMode == KEYMODE_APPLICATION))
  2101.     {
  2102.         STATIC STRPTR StringTable[22][2] =
  2103.         {
  2104.             "0",    "\033Op",
  2105.             "1",    "\033Oq",
  2106.             "2",    "\033Or",
  2107.             "3",    "\033Os",
  2108.             "4",    "\033Ot",
  2109.             "5",    "\033Ou",
  2110.             "6",    "\033Ov",
  2111.             "7",    "\033Ow",
  2112.             "8",    "\033Ox",
  2113.             "9",    "\033Oy",
  2114.             "-",    "\033Om",
  2115.             "+",    "\033Ol",    /* This should really be a comma */
  2116.             ".",    "\033On",
  2117.  
  2118.             "(",    "\033OP",
  2119.             "[",    "\033OP",
  2120.             "{",    "\033OP",
  2121.             "]",    "\033OQ",
  2122.             ")",    "\033OQ",
  2123.             "}",    "\033OQ",
  2124.             "/",    "\033OR",
  2125.             "*",    "\033OS",
  2126.  
  2127.             "\r",    "\033OM"
  2128.         };
  2129.  
  2130.         STATIC struct { UBYTE Code; STRPTR String; } CodeTable[18] =
  2131.         {
  2132.             0x0F,    "\033Op",    /* "0" */
  2133.             0x1D,    "\033Oq",    /* "1" */
  2134.             0x1E,    "\033Or",    /* "2" */
  2135.             0x1F,    "\033Os",    /* "3" */
  2136.             0x2D,    "\033Ot",    /* "4" */
  2137.             0x2E,    "\033Ou",    /* "5" */
  2138.             0x2F,    "\033Ov",    /* "6" */
  2139.             0x3D,    "\033Ow",    /* "7" */
  2140.             0x3E,    "\033Ox",    /* "8" */
  2141.             0x3F,    "\033Oy",    /* "9" */
  2142.             0x4A,    "\033Om",    /* "-" */
  2143.             0x5E,    "\033Ol",    /* "+", but this should really be a comma */
  2144.             0x3C,    "\033On",    /* "." */
  2145.  
  2146.             0x5A,    "\033OP",    /* "[" */
  2147.             0x5B,    "\033OQ",    /* "]" */
  2148.             0x5C,    "\033OR",    /* "/" */
  2149.             0x5D,    "\033OS",    /* "*" */
  2150.  
  2151.             0x43,    "\033OM"    /* <cr> */
  2152.         };
  2153.  
  2154.         STRPTR    String = NULL;
  2155.         LONG    i;
  2156.  
  2157.         for(i = 0 ; i < 22 ; i++)
  2158.         {
  2159.             if(Char == StringTable[i][0][0])
  2160.             {
  2161.                 String = StringTable[i][1];
  2162.  
  2163.                 break;
  2164.             }
  2165.         }
  2166.  
  2167.         if(!String)
  2168.         {
  2169.             for(i = 0 ; i < 18 ; i++)
  2170.             {
  2171.                 if(Code == CodeTable[i].Code)
  2172.                 {
  2173.                     String = CodeTable[i].String;
  2174.  
  2175.                     break;
  2176.                 }
  2177.             }
  2178.         }
  2179.  
  2180.         if(String)
  2181.         {
  2182.             if(ClipInput)
  2183.             {
  2184.                 CloseClip();
  2185.  
  2186.                 ClipInput = ClipXerox = ClipPrefix = FALSE;
  2187.             }
  2188.  
  2189.             SerWrite(String,strlen(String));
  2190.  
  2191.             Len = 0;
  2192.         }
  2193.     }
  2194.  
  2195.         /* This looks like a raw, or better, now cooked key. */
  2196.  
  2197.     if(Len)
  2198.     {
  2199.         switch(CharType[Char])
  2200.         {
  2201.             case CHAR_HELP:
  2202.  
  2203.                 GuideDisplay(CONTEXT_MAIN);
  2204.  
  2205.                 Len = 0;
  2206.  
  2207.                 break;
  2208.  
  2209.             case CHAR_CURSOR:
  2210.  
  2211.                 if(ClipInput)
  2212.                 {
  2213.                     CloseClip();
  2214.  
  2215.                     ClipInput = ClipXerox = ClipPrefix = FALSE;
  2216.                 }
  2217.  
  2218.                     /* If in cursor key applications mode,
  2219.                      * send the corresponding string.
  2220.                      */
  2221.  
  2222.                 if(Config->EmulationConfig->CursorMode == KEYMODE_APPLICATION)
  2223.                 {
  2224.                     STATIC STRPTR CursorTable[4] =
  2225.                     {
  2226.                         "\033OA",
  2227.                         "\033OB",
  2228.                         "\033OC",
  2229.                         "\033OD"
  2230.                     };
  2231.  
  2232.                     SerWrite(CursorTable[Char - CUP],3);
  2233.                 }
  2234.                 else
  2235.                 {
  2236.                     LONG QualType;
  2237.  
  2238.                         /* Find the appropriate qualifier. */
  2239.  
  2240.                     if(Qualifier & SHIFT_KEY)
  2241.                         QualType = 1;
  2242.                     else
  2243.                     {
  2244.                         if(Qualifier & ALT_KEY)
  2245.                             QualType = 2;
  2246.                         else
  2247.                         {
  2248.                             if(Qualifier & CONTROL_KEY)
  2249.                                 QualType = 3;
  2250.                             else
  2251.                                 QualType = 0;
  2252.                         }
  2253.                     }
  2254.  
  2255.                         /* Send the corresponding string. */
  2256.  
  2257.                     SerialCommand(CursorKeys->Keys[QualType][Char - CUP]);
  2258.                 }
  2259.  
  2260.                 Len = 0;
  2261.  
  2262.                 break;
  2263.  
  2264.                 /* Any function key pressed? */
  2265.  
  2266.             case CHAR_FUNCTION:
  2267.  
  2268.                 if(ClipInput)
  2269.                 {
  2270.                     CloseClip();
  2271.  
  2272.                     ClipInput = ClipXerox = ClipPrefix = FALSE;
  2273.                 }
  2274.  
  2275.                 if(Qualifier & CONTROL_KEY)
  2276.                     SerialCommand(MacroKeys->Keys[3][Char - FN1]);
  2277.                 else
  2278.                 {
  2279.                     if(Qualifier & ALT_KEY)
  2280.                         SerialCommand(MacroKeys->Keys[2][Char - FN1]);
  2281.                     else
  2282.                     {
  2283.                         if(Qualifier & SHIFT_KEY)
  2284.                             SerialCommand(MacroKeys->Keys[1][Char - FN1]);
  2285.                         else
  2286.                             SerialCommand(MacroKeys->Keys[0][Char - FN1]);
  2287.                     }
  2288.                 }
  2289.  
  2290.                 Len = 0;
  2291.  
  2292.                 break;
  2293.  
  2294.                 /* Anything else? */
  2295.  
  2296.             default:
  2297.  
  2298.                 if(Len == 1 && Char == '\r' && Recording && !RecordingLine && (Qualifier & SHIFT_KEY))
  2299.                 {
  2300.                     RememberInputText("\r",1);
  2301.  
  2302.                     Len = 0;
  2303.  
  2304.                     PopStatus();
  2305.                     PushStatus(STATUS_RECORDING_LINE);
  2306.  
  2307.                     RecordingLine = TRUE;
  2308.  
  2309.                     RememberResetInput();
  2310.  
  2311.                     RememberOutput = FALSE;
  2312.                     RememberInput = TRUE;
  2313.  
  2314.                     CheckItem(MEN_RECORD_LINE,TRUE);
  2315.                 }
  2316.  
  2317.                 break;
  2318.         }
  2319.  
  2320.             /* Any characters to send? */
  2321.  
  2322.         if(Len)
  2323.             SendInputTextBuffer(InputBuffer,Len,TRUE,FALSE);
  2324.     }
  2325. }
  2326.  
  2327.     /* HandleSerialCheckJob():
  2328.      *
  2329.      *    Handle routine checkup actions.
  2330.      */
  2331.  
  2332. BOOL
  2333. HandleSerialCheckJob(JobNode *UnusedJob)
  2334. {
  2335.         /* Attempt to lock the serial device? */
  2336.  
  2337.     if(PollODU)
  2338.     {
  2339.             /* We don't want to poll too often */
  2340.  
  2341.         if(PollODUCount++ >= (5 + ROUTINE_CHECK_INTERVAL - 1) / ROUTINE_CHECK_INTERVAL)
  2342.         {
  2343.             PollODUCount = 0;
  2344.  
  2345.                 /* Still supporting the locking protocol? */
  2346.  
  2347.             if(Config->SerialConfig->UseOwnDevUnit)
  2348.             {
  2349.                 BlockWindows();
  2350.  
  2351.                     /* Give it a try */
  2352.  
  2353.                 if(LockDevice(Config->SerialConfig->SerialDevice,Config->SerialConfig->UnitNumber,NULL,0))
  2354.                 {
  2355.                         /* Check */
  2356.  
  2357.                     ReopenSerial();
  2358.  
  2359.                     PollODU = FALSE;
  2360.                 }
  2361.  
  2362.                 ReleaseWindows();
  2363.             }
  2364.             else
  2365.                 PollODU = FALSE;
  2366.         }
  2367.     }
  2368.  
  2369.         /* Take a look at the carrier signal. */
  2370.  
  2371.     if(Config->SerialConfig->CheckCarrier && WriteRequest && !Config->SerialConfig->DirectConnection)
  2372.     {
  2373.         UWORD Status = GetSerialStatus();
  2374.  
  2375.             /* Still online? */
  2376.  
  2377.         if(Online)
  2378.         {
  2379.                 /* Carrier detect signal lost? */
  2380.  
  2381.             if(Status & CIAF_COMCD)
  2382.                 SetOnlineState(FALSE);
  2383.         }
  2384.         else
  2385.         {
  2386.                 /* Is the carrier detect signal
  2387.                  * present?
  2388.                  */
  2389.  
  2390.             if(!(Status & CIAF_COMCD))
  2391.                 GoOnline();
  2392.         }
  2393.     }
  2394.  
  2395.         /* Check online time limit. */
  2396.  
  2397.     if(CheckLimit())
  2398.         LaunchRexxAsync(LimitMacro);
  2399.  
  2400.         /* Flush capture file contents to disk,
  2401.          * this routine is executed each minute
  2402.          * in order to store the captured data.
  2403.          */
  2404.  
  2405.     if(BufferFlushCount++ >= (60 + ROUTINE_CHECK_INTERVAL - 1) / ROUTINE_CHECK_INTERVAL)
  2406.     {
  2407.         BufferFlushCount = 0;
  2408.  
  2409.             /* Flush the capture file. */
  2410.  
  2411.         if(FileCapture)
  2412.             BufferFlush(FileCapture);
  2413.     }
  2414.  
  2415.     return(FALSE);
  2416. }
  2417.  
  2418.     /* HandleQueueJob(JobNode *UnusedJob):
  2419.      *
  2420.      *    Process the special message queue.
  2421.      */
  2422.  
  2423. BOOL
  2424. HandleQueueJob(JobNode *UnusedJob)
  2425. {
  2426.     struct DataMsg *Item;
  2427.  
  2428.     if(Item = GetMsgItem(SpecialQueue))
  2429.     {
  2430.         WORD OldEcho,Type;
  2431.  
  2432.         switch(Item->Type)
  2433.         {
  2434.                 /* Output data. */
  2435.  
  2436.             case DATAMSGTYPE_WRITE:
  2437.  
  2438.                 SerWrite(Item->Data,Item->Size);
  2439.                 break;
  2440.  
  2441.                 /* Execute a command. */
  2442.  
  2443.             case DATAMSGTYPE_SERIALCOMMAND:
  2444.  
  2445.                 SerialCommand(Item->Data);
  2446.                 break;
  2447.  
  2448.                 /* Execute a command, but don't echo it. */
  2449.  
  2450.             case DATAMSGTYPE_SERIALCOMMANDNOECHO:
  2451.  
  2452.                 OldEcho = Config->SerialConfig->Duplex;
  2453.  
  2454.                 Config->SerialConfig->Duplex = DUPLEX_FULL;
  2455.  
  2456.                 SerialCommand(Item->Data);
  2457.  
  2458.                 Config->SerialConfig->Duplex = OldEcho;
  2459.                 break;
  2460.  
  2461.                 /* Output contents of clipboard */
  2462.  
  2463.             case DATAMSGTYPE_WRITECLIP:
  2464.  
  2465.                 if(!ClipInput)
  2466.                 {
  2467.                     if(!OpenClip(Item->Size))
  2468.                         ClipInput = ClipXerox = TRUE;
  2469.                     else
  2470.                         ClipInput = ClipXerox = FALSE;
  2471.                 }
  2472.  
  2473.                     /* Are we reading input from the clipboard? */
  2474.  
  2475.                 if(ClipInput)
  2476.                 {
  2477.                     UBYTE InputBuffer[256];
  2478.                     LONG Len;
  2479.  
  2480.                     if((Len = GetClip(InputBuffer,sizeof(InputBuffer) - 1)) < 0)
  2481.                     {
  2482.                         CloseClip();
  2483.  
  2484.                         ClipInput = FALSE;
  2485.  
  2486.                         if(ClipXerox)
  2487.                         {
  2488.                             if(Config->ClipConfig->InsertSuffix[0])
  2489.                                 SerialCommand(Config->ClipConfig->InsertSuffix);
  2490.  
  2491.                             ClipXerox = FALSE;
  2492.                         }
  2493.  
  2494.                         ClipPrefix = FALSE;
  2495.                     }
  2496.                     else
  2497.                     {
  2498.                         if(!ClipPrefix && ClipXerox)
  2499.                         {
  2500.                             if(Config->ClipConfig->InsertPrefix[0])
  2501.                                 SerialCommand(Config->ClipConfig->InsertPrefix);
  2502.  
  2503.                             ClipPrefix = TRUE;
  2504.                         }
  2505.  
  2506.                         if(Len > 0)
  2507.                             SendInputTextBuffer(InputBuffer,Len,FALSE,Config->ClipConfig->ConvertLF);
  2508.                     }
  2509.                 }
  2510.  
  2511.                 break;
  2512.  
  2513.                 /* Start an upload */
  2514.  
  2515.             case DATAMSGTYPE_UPLOAD:
  2516.  
  2517.                 Type = Item->Size;
  2518.  
  2519.                 DeleteMsgItem((struct MsgItem *)Item);
  2520.                 Item = NULL;
  2521.  
  2522.                 HandleUpload(Type);
  2523.                 break;
  2524.  
  2525.                 /* Call a menu item */
  2526.  
  2527.             case DATAMSGTYPE_MENU:
  2528.  
  2529.                 HandleMenuCode((ULONG)Item->Size,(ULONG)Item->Data);
  2530.  
  2531.                 break;
  2532.  
  2533.                 /* Rendezvous with external process */
  2534.  
  2535.             case DATAMSGTYPE_RENDEZVOUS:
  2536.  
  2537.                 if(ReadRequest && WriteRequest)
  2538.                 {
  2539.                         /* Abort serial I/O processing */
  2540.  
  2541.                     ClearSerial();
  2542.  
  2543.                     BlockWindows();
  2544.  
  2545.                         /* Return the message, caution, we're not ready yet */
  2546.  
  2547.                     Forbid();
  2548.  
  2549.                     DeleteMsgItem((struct MsgItem *)Item);
  2550.  
  2551.                     Item = NULL;
  2552.  
  2553.                         /* Prepare to wait... */
  2554.  
  2555.                     WaitForHandshake();
  2556.  
  2557.                         /* Pick up the queue */
  2558.  
  2559.                     RestartSerial();
  2560.  
  2561.                     Permit();
  2562.  
  2563.                     ReleaseWindows();
  2564.                 }
  2565.  
  2566.                 break;
  2567.  
  2568.                 /* Discard current buffer contents */
  2569.  
  2570.             case DATAMSGTYPE_CLEARBUFFER:
  2571.  
  2572.                 FreeBuffer();
  2573.                 break;
  2574.  
  2575.                 /* Redial current dial list */
  2576.  
  2577.             case DATAMSGTYPE_REDIAL:
  2578.  
  2579.                 if(!Online)
  2580.                     DoDial = DIAL_LIST;
  2581.  
  2582.                 break;
  2583.  
  2584.                 /* Hang up the line */
  2585.  
  2586.             case DATAMSGTYPE_HANGUP:
  2587.  
  2588.                 FullHangup(FALSE);
  2589.                 break;
  2590.  
  2591.                 /* Go to online state */
  2592.  
  2593.             case DATAMSGTYPE_GOONLINE:
  2594.  
  2595.                 if(!Online)
  2596.                     GoOnline();
  2597.  
  2598.                 break;
  2599.  
  2600.                 /* Dial a list of numbers */
  2601.  
  2602.             case DATAMSGTYPE_DIAL:
  2603.  
  2604.                 ReadyToDial((struct DataDialMsg *)Item);
  2605.                 break;
  2606.  
  2607.                 /* Output data as if it had come from the main window. */
  2608.  
  2609.             case DATAMSGTYPE_WRITESTRING:
  2610.  
  2611.                 SendInputTextBuffer(Item->Data,Item->Size,TRUE,TRUE);
  2612.                 break;
  2613.  
  2614.                 /* Output data as if it had come from the main window. */
  2615.  
  2616.             case DATAMSGTYPE_WRITESTRING_NOECHO:
  2617.  
  2618.                 OldEcho = Config->SerialConfig->Duplex;
  2619.  
  2620.                 Config->SerialConfig->Duplex = DUPLEX_FULL;
  2621.  
  2622.                 SendInputTextBuffer(Item->Data,Item->Size,TRUE,TRUE);
  2623.  
  2624.                 Config->SerialConfig->Duplex = OldEcho;
  2625.                 break;
  2626.         }
  2627.  
  2628.         if(Item)
  2629.             DeleteMsgItem((struct MsgItem *)Item);
  2630.  
  2631.         return(TRUE);
  2632.     }
  2633.     else
  2634.         return(FALSE);
  2635. }
  2636.  
  2637.     /* HandleOwnDevUnitJob():
  2638.      *
  2639.      *    Deal with the OwnDevUnit signal notification.
  2640.      */
  2641.  
  2642. BOOL
  2643. HandleOwnDevUnitJob(JobNode *UnusedJob)
  2644. {
  2645.     DB(kprintf("handle ODU\n"));
  2646.  
  2647.     if(!Online || !ReadPort || (Online && Config->SerialConfig->ReleaseODUWhenOnline))
  2648.     {
  2649.         if(Config->SerialConfig->SatisfyODURequests == ODU_RELEASE)
  2650.         {
  2651.             DB(kprintf("ODU release\n"));
  2652.             LocalReleaseSerial();
  2653.         }
  2654.  
  2655.         if(Config->SerialConfig->SatisfyODURequests == ODU_WAIT)
  2656.         {
  2657.             BOOL Continue,SerialClosed;
  2658.             APTR OldPtr;
  2659.  
  2660.             DB(kprintf("ODU wait\n"));
  2661.  
  2662.             ChangeWindowPtr(&OldPtr,(APTR)Window);
  2663.  
  2664.                 /* This might happen if an ARexx user
  2665.                  * released the serial device and
  2666.                  * failed to reopen it.
  2667.                  */
  2668.  
  2669.             if(ReadPort)
  2670.                 SerialClosed = FALSE;
  2671.             else
  2672.                 SerialClosed = TRUE;
  2673.  
  2674.             BlockWindows();
  2675.  
  2676.                 /* Prevent catastrophes! */
  2677.  
  2678.             if(Online && !SerialClosed && !Config->SerialConfig->ReleaseODUWhenOnline)
  2679.             {
  2680.                 if(!ShowRequest(Window,LocaleString(MSG_TERMMAIN_YOU_ARE_STILL_ONLINE_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  2681.                     Continue = FALSE;
  2682.                 else
  2683.                     Continue = TRUE;
  2684.             }
  2685.             else
  2686.                 Continue = TRUE;
  2687.  
  2688.             if(Continue)
  2689.             {
  2690.                 if(!SerialClosed)
  2691.                 {
  2692.                     ClearSerial();
  2693.  
  2694.                     DeleteSerial();
  2695.                 }
  2696.             }
  2697.  
  2698.             RestoreWindowPtr(OldPtr);
  2699.  
  2700.             ReleaseWindows();
  2701.  
  2702.                 /* Start polling for the device to become */
  2703.                 /* available again */
  2704.  
  2705.             PollODU = TRUE;
  2706.         }
  2707.     }
  2708.  
  2709.     DB(kprintf("ODU done\n"));
  2710.  
  2711.     return(FALSE);
  2712. }
  2713.  
  2714.     /* HandleWindowJob(JobNode *UnusedJob):
  2715.      *
  2716.      *    Just makes a call to HandleWindow().
  2717.      */
  2718.  
  2719. BOOL
  2720. HandleWindowJob(JobNode *UnusedJob)
  2721. {
  2722.     return(HandleWindow());
  2723. }
  2724.  
  2725.     /* HandleWindowAndXEMJob(JobNode *UnusedJob):
  2726.      *
  2727.      *    Calls both HandleXEM() and HandleWindow().
  2728.      */
  2729.  
  2730. BOOL
  2731. HandleWindowAndXEMJob(JobNode *UnusedJob)
  2732. {
  2733.     HandleXEM();
  2734.  
  2735.     return(HandleWindow());
  2736. }
  2737.  
  2738.     /* HandleWindow():
  2739.      *
  2740.      *    This funny part checks the window(s) for incoming
  2741.      *    user input. Menus are handled elsewhere.
  2742.      */
  2743.  
  2744. BOOL
  2745. HandleWindow()
  2746. {
  2747.     STATIC ULONG    ClickSeconds,ClickMicros;
  2748.     STATIC ULONG    LastSeconds,LastMicros;
  2749.     STATIC BOOL        TestingDoubleClick;
  2750.  
  2751.     struct IntuiMessage    *Message;
  2752.     ULONG                 MsgClass,Code,Qualifier,Seconds,Micros;
  2753.     LONG                 MouseX,MouseY,Len,GadgetID;
  2754.     struct Gadget        *Gadget;
  2755.     UBYTE                 Char,InputBuffer[256];
  2756.     struct Window        *IDCMPWindow;
  2757.     BOOL                 Result,WindowJustActivated;
  2758.  
  2759.     Result                = FALSE;
  2760.     WindowJustActivated    = FALSE;
  2761.  
  2762.         /* Are we reading input from the clipboard? */
  2763.  
  2764.     if(ClipInput)
  2765.     {
  2766.         LONG Length = GetClip(InputBuffer,sizeof(InputBuffer) - 1);
  2767.  
  2768.         if(Length < 0)
  2769.         {
  2770.             CloseClip();
  2771.  
  2772.             ClipInput = FALSE;
  2773.  
  2774.             if(ClipXerox)
  2775.             {
  2776.                 if(Config->ClipConfig->InsertSuffix[0])
  2777.                     SerialCommand(Config->ClipConfig->InsertSuffix);
  2778.  
  2779.                 ClipXerox = FALSE;
  2780.             }
  2781.  
  2782.             ClipPrefix = FALSE;
  2783.         }
  2784.         else
  2785.         {
  2786.             if(!ClipPrefix && ClipXerox)
  2787.             {
  2788.                 if(Config->ClipConfig->InsertPrefix[0])
  2789.                     SerialCommand(Config->ClipConfig->InsertPrefix);
  2790.  
  2791.                 ClipPrefix = TRUE;
  2792.             }
  2793.  
  2794.             if(Length > 0)
  2795.                 SendInputTextBuffer(InputBuffer,Length,FALSE,Config->ClipConfig->ConvertLF);
  2796.  
  2797.             Result = TRUE;
  2798.         }
  2799.     }
  2800.  
  2801.         /* Any news in the mail? */
  2802.  
  2803.     if(Message = (struct IntuiMessage *)GetMsg(Window->UserPort))
  2804.     {
  2805.             /* A click into the window should activate it, but
  2806.              * we don't want to have the character snapping activated
  2807.              * under these conditions. In this case we rely upon
  2808.              * Intuition sending the IDCMP_ACTIVEWINDOW and
  2809.              * IDCMP_MOUSEBUTTONS event marked with the same
  2810.              * creation time stamp. Even if the Intuition
  2811.              * implementation should change no harm should
  2812.              * be done.
  2813.              */
  2814.  
  2815.         Seconds    = Message->Seconds;
  2816.         Micros    = Message->Micros;
  2817.  
  2818.         if(Seconds == LastSeconds && Micros == LastMicros && Message->IDCMPWindow == Window)
  2819.         {
  2820.             if(Message->Class == IDCMP_ACTIVEWINDOW || Message->Class == IDCMP_MOUSEBUTTONS)
  2821.                 WindowJustActivated = TRUE;
  2822.         }
  2823.  
  2824.         LastSeconds    = Seconds;
  2825.         LastMicros    = Micros;
  2826.  
  2827.             /* Pick up the pieces. */
  2828.  
  2829.         MsgClass    = Message->Class;
  2830.         Code        = Message->Code;
  2831.         Qualifier    = Message->Qualifier;
  2832.         Gadget        = (struct Gadget *)Message->IAddress;
  2833.  
  2834.         MouseX        = Message->MouseX;
  2835.         MouseY        = Message->MouseY;
  2836.  
  2837.         IDCMPWindow    = Message->IDCMPWindow;
  2838.  
  2839.         Len        = 0;
  2840.         Char    = 0;
  2841.  
  2842.         switch(MsgClass)
  2843.         {
  2844.             case IDCMP_IDCMPUPDATE:
  2845.  
  2846.                 GadgetID = GetTagData(GA_ID,0,(struct TagItem *)Gadget);
  2847.                 break;
  2848.  
  2849.             case IDCMP_GADGETUP:
  2850.             case IDCMP_GADGETDOWN:
  2851.  
  2852.                 GadgetID = Gadget->GadgetID;
  2853.                 break;
  2854.  
  2855.             case IDCMP_RAWKEY:
  2856.  
  2857.                     /* Perform key conversion. */
  2858.  
  2859.                 if(XEmulatorBase)
  2860.                 {
  2861.                     if(Len = XEmulatorUserMon(XEM_IO,InputBuffer,sizeof(InputBuffer) - 1,Message))
  2862.                         Char = InputBuffer[0];
  2863.                 }
  2864.                 else
  2865.                     Char = KeyConvert(Message,InputBuffer,&Len);
  2866.  
  2867.                 /* Falls through to... */
  2868.  
  2869.             default:
  2870.  
  2871.                 GadgetID = 0;
  2872.                 break;
  2873.         }
  2874.  
  2875.         ReplyMsg((struct Message *)Message);
  2876.  
  2877.             /* The following messages originated from
  2878.              * the fast! macro panel.
  2879.              */
  2880.  
  2881.         if(IDCMPWindow == FastWindow)
  2882.         {
  2883.             switch(MsgClass)
  2884.             {
  2885.                     /* Close the window. */
  2886.  
  2887.                 case IDCMP_CLOSEWINDOW:
  2888.  
  2889.                     CloseFastWindow();
  2890.                     return(TRUE);
  2891.  
  2892.                     /* Gadget or window size change event. */
  2893.  
  2894.                 case IDCMP_GADGETUP:
  2895.                 case IDCMP_NEWSIZE:
  2896.  
  2897.                     HandleFastWindowGadget(MsgClass,Code);
  2898.                     return(TRUE);
  2899.             }
  2900.         }
  2901.  
  2902.             /* Status window activated? */
  2903.  
  2904.         if(IDCMPWindow == StatusWindow)
  2905.         {
  2906.             switch(MsgClass)
  2907.             {
  2908.                 case IDCMP_ACTIVEWINDOW:
  2909.  
  2910.                     if(!Config->ScreenConfig->SplitStatus)
  2911.                         NormalCursor();
  2912.  
  2913.                     break;
  2914.  
  2915.                 case IDCMP_CLOSEWINDOW:
  2916.  
  2917.                     ShakeHands((struct Task *)StatusProcess,SIG_CLOSEWINDOW);
  2918.  
  2919.                     ClearMenuStrip(StatusWindow);
  2920.                     CloseWindowSafely(StatusWindow);
  2921.  
  2922.                     StatusWindow = NULL;
  2923.                     break;
  2924.             }
  2925.         }
  2926.  
  2927.             /* What about the matrix window? */
  2928.  
  2929.         if(IDCMPWindow == MatrixWindow)
  2930.         {
  2931.             if(DispatchMatrixWindow(&MsgClass,Code,Qualifier,Char))
  2932.                 CloseMatrixWindow();
  2933.         }
  2934.  
  2935.             /* Main window message? */
  2936.  
  2937.         if(IDCMPWindow == Window)
  2938.         {
  2939.             switch(MsgClass)
  2940.             {
  2941.                 case IDCMP_GADGETUP:
  2942.  
  2943.                     if(GadgetID == CHAT_GadgetID)
  2944.                         HandleChatGadget(Code);
  2945.  
  2946.                     break;
  2947.  
  2948.                 case IDCMP_GADGETDOWN:
  2949.  
  2950.                     if(GadgetID == CHAT_GadgetID)
  2951.                         MarkChatGadgetAsActive();
  2952.  
  2953.                     break;
  2954.  
  2955.                 case IDCMP_INACTIVEWINDOW:
  2956.  
  2957.                     WindowMarkerInterrupt();
  2958.  
  2959.                     GhostCursor();
  2960.  
  2961.                     break;
  2962.  
  2963.                 case IDCMP_ACTIVEWINDOW:
  2964.  
  2965.                         /* Take care of the chat gadget if necessary */
  2966.  
  2967.                     ActivateChat(TRUE);
  2968.  
  2969.                     NormalCursor();
  2970.  
  2971.                     break;
  2972.  
  2973.                 case IDCMP_NEWSIZE:
  2974.  
  2975.                         /* Is a window clipping region installed? */
  2976.  
  2977.                     if(ClipRegion)
  2978.                     {
  2979.                         struct Rectangle RegionRectangle;
  2980.  
  2981.                             /* Install old region. */
  2982.  
  2983.                         InstallClipRegion(Window->WLayer,OldRegion);
  2984.  
  2985.                             /* Fill in the clipping rectangle. */
  2986.  
  2987.                         RegionRectangle.MinX = Window->BorderLeft;
  2988.                         RegionRectangle.MinY = Window->BorderTop;
  2989.                         RegionRectangle.MaxX = Window->Width - (Window->BorderRight + 1);
  2990.                         RegionRectangle.MaxY = Window->Height - (Window->BorderBottom + 1);
  2991.  
  2992.                             /* Clear previous clipping region. */
  2993.  
  2994.                         ClearRegion(ClipRegion);
  2995.  
  2996.                             /* Set new clipping region. */
  2997.  
  2998.                         OrRectRegion(ClipRegion,&RegionRectangle);
  2999.  
  3000.                             /* Install new clipping region. */
  3001.  
  3002.                         OldRegion = InstallClipRegion(Window->WLayer,ClipRegion);
  3003.                     }
  3004.  
  3005.                     ForceStatusUpdate();
  3006.  
  3007.                     HandleMenuCode(MEN_RESET_TERMINAL,Qualifier);
  3008.  
  3009.                         /* Take care of the chat gadget if necessary */
  3010.  
  3011.                     ActivateChat(TRUE);
  3012.  
  3013.                     TTYResize();
  3014.  
  3015.                     break;
  3016.  
  3017.                 case IDCMP_CLOSEWINDOW:
  3018.  
  3019.                     HandleMenuCode(MEN_QUIT,Qualifier);
  3020.                     break;
  3021.  
  3022.                 case IDCMP_MOUSEMOVE:
  3023.  
  3024.                     WindowMarkerMoveMouse();
  3025.                     break;
  3026.  
  3027.                 case IDCMP_MOUSEBUTTONS:
  3028.  
  3029.                     if(Code == SELECTUP)
  3030.                         ActivateChat(TRUE);
  3031.  
  3032.                     if((!WindowJustActivated || Code != SELECTDOWN) && (!XEmulatorBase || Config->TerminalConfig->EmulationMode != EMULATION_EXTERNAL))
  3033.                     {
  3034.                         switch(Code)
  3035.                         {
  3036.                             case SELECTUP:
  3037.  
  3038.                                 WindowMarkerInterrupt();
  3039.                                 break;
  3040.  
  3041.                             case SELECTDOWN:
  3042.  
  3043.                                 MouseX -= WindowLeft;
  3044.  
  3045.                                 if(MouseX < 0)
  3046.                                     MouseX = 0;
  3047.  
  3048.                                 if(MouseX > WindowWidth - 1)
  3049.                                     MouseX = WindowWidth - 1;
  3050.  
  3051.                                 MouseY -= WindowTop;
  3052.  
  3053.                                 if(MouseY < 0)
  3054.                                     MouseY = 0;
  3055.  
  3056.                                 if(MouseY > WindowHeight - 1)
  3057.                                     MouseY = WindowHeight - 1;
  3058.  
  3059.                                 if(Qualifier & CONTROL_KEY)
  3060.                                 {
  3061.                                     LONG FirstX,FirstY;
  3062.  
  3063.                                     FirstX = (MouseX * CharCellDenominator) / (TextFontWidth * CharCellNominator);
  3064.                                     FirstY = MouseY / TextFontHeight;
  3065.  
  3066.                                     if(FirstX < RasterWidth && FirstY < RasterHeight)
  3067.                                     {
  3068.                                         UBYTE LocalChar[2];
  3069.  
  3070.                                         SafeObtainSemaphoreShared(&RasterSemaphore);
  3071.  
  3072.                                         LocalChar[0] = Raster[FirstY * RasterWidth + FirstX];
  3073.  
  3074.                                         ReleaseSemaphore(&RasterSemaphore);
  3075.  
  3076.                                         if(LocalChar[0])
  3077.                                         {
  3078.                                             LONG Len;
  3079.  
  3080.                                             if(Qualifier & SHIFT_KEY)
  3081.                                             {
  3082.                                                 LocalChar[1] = '\r';
  3083.                                                 Len = 2;
  3084.                                             }
  3085.                                             else
  3086.                                                 Len = 1;
  3087.  
  3088.                                             SendInputTextBuffer(LocalChar,Len,TRUE,TRUE);
  3089.                                         }
  3090.                                     }
  3091.  
  3092.                                     return(TRUE);
  3093.                                 }
  3094.  
  3095.                                 if((Qualifier & ALT_KEY) && (Qualifier & IEQUALIFIER_LEFTBUTTON))
  3096.                                 {
  3097.                                     LONG DeltaX,DeltaY;
  3098.  
  3099.                                     ObtainSemaphore(&TerminalSemaphore);
  3100.  
  3101.                                     DeltaX = (MouseX * CharCellDenominator) / (TextFontWidth * CharCellNominator)  - CursorX;
  3102.                                     DeltaY = MouseY / TextFontHeight - CursorY;
  3103.  
  3104.                                     ReleaseSemaphore(&TerminalSemaphore);
  3105.  
  3106.                                     if(DeltaX || DeltaY)
  3107.                                     {
  3108.                                         if(DeltaX > 0)
  3109.                                         {
  3110.                                             DeltaX++;
  3111.  
  3112.                                             while(DeltaX--)
  3113.                                                 SerWrite("\33[C",3);
  3114.                                         }
  3115.  
  3116.                                         if(DeltaX < 0)
  3117.                                         {
  3118.                                             while(DeltaX++)
  3119.                                                 SerWrite("\33[D",3);
  3120.                                         }
  3121.  
  3122.                                         if(DeltaY > 0)
  3123.                                         {
  3124.                                             DeltaY++;
  3125.  
  3126.                                             while(DeltaY--)
  3127.                                                 SerWrite("\33[B",3);
  3128.                                         }
  3129.  
  3130.                                         if(DeltaY < 0)
  3131.                                         {
  3132.                                             while(DeltaY++)
  3133.                                                 SerWrite("\33[A",3);
  3134.                                         }
  3135.                                     }
  3136.  
  3137.                                     return(TRUE);
  3138.                                 }
  3139.  
  3140.                                 if(TestingDoubleClick)
  3141.                                 {
  3142.                                     ULONG CurrentSeconds,CurrentMicros;
  3143.  
  3144.                                     TestingDoubleClick = FALSE;
  3145.  
  3146.                                     CurrentTime(&CurrentSeconds,&CurrentMicros);
  3147.  
  3148.                                     if(DoubleClick(ClickSeconds,ClickMicros,CurrentSeconds,CurrentMicros))
  3149.                                     {
  3150.                                         WindowMarkWord();
  3151.  
  3152.                                         return(TRUE);
  3153.                                     }
  3154.                                 }
  3155.                                 else
  3156.                                 {
  3157.                                     TestingDoubleClick = TRUE;
  3158.  
  3159.                                     CurrentTime(&ClickSeconds,&ClickMicros);
  3160.                                 }
  3161.  
  3162.                                 WindowMarkerStart(Qualifier);
  3163.                                 break;
  3164.                         }
  3165.                     }
  3166.  
  3167.                     break;
  3168.             }
  3169.         }
  3170.  
  3171.             /* Now for general information. */
  3172.  
  3173.         switch(MsgClass)
  3174.         {
  3175.             case IDCMP_REFRESHWINDOW:
  3176.  
  3177.                 BeginRefresh(IDCMPWindow);
  3178.                 EndRefresh(IDCMPWindow,TRUE);
  3179.                 break;
  3180.  
  3181.             case IDCMP_RAWKEY:
  3182.  
  3183.                 HandleKeyboardInput(Char,Code,Qualifier,InputBuffer,Len);
  3184.                 break;
  3185.  
  3186.                 /* A menu item was selected. */
  3187.  
  3188.             case IDCMP_MENUPICK:
  3189.  
  3190.                 HandleMenu(Code,Qualifier);
  3191.  
  3192.                     /* Take care of the chat gadget if necessary */
  3193.  
  3194.                 ActivateChat(TRUE);
  3195.  
  3196.                 break;
  3197.  
  3198.                 /* Menu help is required. */
  3199.  
  3200.             case IDCMP_MENUHELP:
  3201.  
  3202.                 if(MENUNUM(Code) == NOMENU || MENUNUM(Code) > 9 || ITEMNUM(Code) == NOITEM)
  3203.                     GuideDisplay(CONTEXT_MAIN_MENU);
  3204.                 else
  3205.                     GuideDisplay(CONTEXT_PROJECT_MEN + MENUNUM(Code));
  3206.  
  3207.                 break;
  3208.         }
  3209.  
  3210.         return(TRUE);
  3211.     }
  3212.  
  3213.     return(Result);
  3214. }
  3215.  
  3216.     /* HandleMenuCode(ULONG Code,ULONG Qualifier):
  3217.      *
  3218.      *    Handle each function associated with a menu code.
  3219.      */
  3220.  
  3221. VOID
  3222. HandleMenuCode(ULONG Code,ULONG Qualifier)
  3223. {
  3224.     struct FileRequester    *FileRequest;
  3225.     UBYTE                     DummyBuffer[MAX_FILENAME_LENGTH];
  3226.  
  3227.     struct Window            *ReqWindow;
  3228.     struct EasyStruct         Easy;
  3229.  
  3230.     BPTR                     SomeFile;
  3231.     APTR                     OldPtr;
  3232.  
  3233.     BOOL                     Checked;
  3234.  
  3235.     switch(Code)
  3236.     {
  3237.             /* Save screen as IFF-ILBM file. */
  3238.  
  3239.         case MEN_SAVE_AS_PICTURE:
  3240.  
  3241.             BlockWindows();
  3242.  
  3243.             DummyBuffer[0] = 0;
  3244.  
  3245.             if(FileRequest = SaveFile(Window,LocaleString(MSG_TERMMAIN_SAVE_SCREEN_IFF_TXT),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  3246.             {
  3247.                 FreeAslRequest(FileRequest);
  3248.  
  3249.                 if(!SaveWindow(DummyBuffer,Window))
  3250.                     ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
  3251.             }
  3252.  
  3253.             ReleaseWindows();
  3254.  
  3255.             break;
  3256.  
  3257.             /* Save screen as ASCII file. */
  3258.  
  3259.         case MEN_SAVE_AS_TEXT:
  3260.  
  3261.             BlockWindows();
  3262.  
  3263.             DummyBuffer[0] = 0;
  3264.  
  3265.             if(FileRequest = SaveFile(Window,LocaleString(MSG_TERMMAIN_SAVE_SCREEN_ASCII_TXT),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  3266.             {
  3267.                 LONG Error = 0;
  3268.  
  3269.                 FreeAslRequest(FileRequest);
  3270.  
  3271.                 SomeFile = NULL;
  3272.  
  3273.                 if(GetFileSize(DummyBuffer))
  3274.                 {
  3275.                     switch(ShowRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  3276.                     {
  3277.                         case 0:
  3278.  
  3279.                             SetIoErr(0);
  3280.                             break;
  3281.  
  3282.                         case 1:
  3283.  
  3284.                             SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  3285.                             break;
  3286.  
  3287.                         case 2:
  3288.  
  3289.                             SomeFile = OpenToAppend(DummyBuffer,NULL);
  3290.                             break;
  3291.                     }
  3292.                 }
  3293.                 else
  3294.                     SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  3295.  
  3296.                 if(SomeFile)
  3297.                 {
  3298.                     UBYTE *Buffer;
  3299.                     LONG i,j;
  3300.  
  3301.                     for(i = 0 ; i < RasterHeight ; i++)
  3302.                     {
  3303.                         Buffer = &Raster[i * RasterWidth];
  3304.  
  3305.                         j = RasterWidth - 1;
  3306.  
  3307.                         while(j >= 0 && Buffer[j] == ' ')
  3308.                             j--;
  3309.  
  3310.                         if(j >= 0)
  3311.                         {
  3312.                             SetIoErr(0);
  3313.  
  3314.                             if(FWrite(SomeFile,Buffer,j + 1,1) < 1)
  3315.                             {
  3316.                                 Error = IoErr();
  3317.  
  3318.                                 break;
  3319.                             }
  3320.                         }
  3321.  
  3322.                         SetIoErr(0);
  3323.  
  3324.                         if(FWrite(SomeFile,"\n",1,1) < 1)
  3325.                         {
  3326.                             Error = IoErr();
  3327.  
  3328.                             break;
  3329.                         }
  3330.                     }
  3331.  
  3332.                     Close(SomeFile);
  3333.  
  3334.                     AddProtection(DummyBuffer,FIBF_EXECUTE);
  3335.  
  3336.                     if(Config->MiscConfig->CreateIcons)
  3337.                         AddIcon(DummyBuffer,FILETYPE_TEXT,TRUE);
  3338.                 }
  3339.                 else
  3340.                     Error = IoErr();
  3341.  
  3342.                 if(Error)
  3343.                     ShowError(Window,ERR_SAVE_ERROR,Error,DummyBuffer);
  3344.             }
  3345.  
  3346.             ReleaseWindows();
  3347.  
  3348.             break;
  3349.  
  3350.             /* Print the screen (pure ASCII). */
  3351.  
  3352.         case MEN_PRINT_SCREEN:
  3353.  
  3354.             BlockWindows();
  3355.  
  3356.             if(RasterEnabled)
  3357.                 PrintSomething(PRINT_SCREEN);
  3358.             else
  3359.                 ShowRequest(Window,LocaleString(MSG_TERMMAIN_NO_DATA_TO_PRINT_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  3360.  
  3361.             ReleaseWindows();
  3362.  
  3363.             break;
  3364.  
  3365.             /* Print the screen (graphics). */
  3366.  
  3367.         case MEN_PRINT_SCREEN_AS_GFX:
  3368.  
  3369.             BlockWindows();
  3370.  
  3371.             PrintScreenGfx();
  3372.  
  3373.             ReleaseWindows();
  3374.  
  3375.             break;
  3376.  
  3377.             /* Print the clipboard contents. */
  3378.  
  3379.         case MEN_PRINT_CLIP:
  3380.  
  3381.             BlockWindows();
  3382.  
  3383.             PrintSomething(PRINT_CLIP);
  3384.  
  3385.             ReleaseWindows();
  3386.  
  3387.             break;
  3388.  
  3389.             /* Open/close the terminal capture file. */
  3390.  
  3391.         case MEN_CAPTURE_TO_FILE:
  3392.  
  3393.             if(FileCapture)
  3394.                 CloseFileCapture();
  3395.             else
  3396.                 OpenFileCapture(FALSE);
  3397.  
  3398.             break;
  3399.  
  3400.             /* Open/close the terminal capture file. */
  3401.  
  3402.         case MEN_CAPTURE_TO_RAW_FILE:
  3403.  
  3404.             if(FileCapture)
  3405.                 CloseFileCapture();
  3406.             else
  3407.                 OpenFileCapture(TRUE);
  3408.  
  3409.             break;
  3410.  
  3411.             /* Start/terminate the printer
  3412.              * capture.
  3413.              */
  3414.  
  3415.         case MEN_CAPTURE_TO_PRINTER:
  3416.  
  3417.             if(PrinterCapture)
  3418.                 ClosePrinterCapture(TRUE);
  3419.             else
  3420.                 OpenPrinterCapture(FALSE);
  3421.  
  3422.             break;
  3423.  
  3424.             /* Iconify the program. */
  3425.  
  3426.         case MEN_ICONIFY:
  3427.  
  3428.             if(Config->MiscConfig->ProtectiveMode)
  3429.             {
  3430.                 if(Online && Config->MiscConfig->ReleaseDevice && !(Qualifier & SHIFT_KEY))
  3431.                 {
  3432.                     BlockWindows();
  3433.  
  3434.                     if(!ShowRequest(Window,LocaleString(MSG_TERMMAIN_YOU_ARE_STILL_ONLINE_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  3435.                     {
  3436.                         ReleaseWindows();
  3437.  
  3438.                         break;
  3439.                     }
  3440.  
  3441.                     ReleaseWindows();
  3442.                 }
  3443.             }
  3444.  
  3445.             ActivateJob(MainJobQueue,IconifyJob);
  3446.  
  3447.             break;
  3448.  
  3449.             /* Say who we are. */
  3450.  
  3451.         case MEN_ABOUT:
  3452.  
  3453.             if(Qualifier & IEQUALIFIER_LSHIFT)
  3454.                 StartTerminalTest(Qualifier);
  3455.             else
  3456.             {
  3457.                 BlockWindows();
  3458.                 ShowAbout(FALSE);
  3459.                 ReleaseWindows();
  3460.             }
  3461.  
  3462.             break;
  3463.  
  3464.             /* Terminate the program. */
  3465.  
  3466.         case MEN_QUIT:
  3467.  
  3468.             if((Qualifier & SHIFT_KEY) || !Config->MiscConfig->ProtectiveMode)
  3469.                 MainTerminated = TRUE;
  3470.             else
  3471.             {
  3472.                 LONG OldLen,Len;
  3473.                 STRPTR Buffer;
  3474.  
  3475.                 OldLen = Len = strlen(LocaleString(MSG_TERMMAIN_REALLY_QUIT_TXT)) + 3;
  3476.  
  3477.                 if(Online)
  3478.                     Len += strlen(LocaleString(MSG_WAIT_PROGRAM_IS_STILL_ONLINE_TXT)) + 4;
  3479.  
  3480.                 if(BufferChanged)
  3481.                     Len += strlen(LocaleString(MSG_WAIT_REVIEW_BUFFER_NOT_SAVED_TXT)) + 4;
  3482.  
  3483.                 if(ConfigChanged)
  3484.                     Len += strlen(LocaleString(MSG_WAIT_CONFIGURATION_HAS_BEEN_CHANGED_TXT)) + 4;
  3485.  
  3486.                 if(PhonebookChanged)
  3487.                     Len += strlen(LocaleString(MSG_WAIT_PHONEBOOK_NOT_SAVED_TXT)) + 4;
  3488.  
  3489.                 if(TranslationChanged)
  3490.                     Len += strlen(LocaleString(MSG_WAIT_TRANSLATION_TABLES_CHANGED_TXT)) + 4;
  3491.  
  3492.                 if(MacroChanged)
  3493.                     Len += strlen(LocaleString(MSG_WAIT_MACRO_KEYS_CHANGED_TXT)) + 4;
  3494.  
  3495.                 if(CursorKeysChanged)
  3496.                     Len += strlen(LocaleString(MSG_WAIT_CURSOR_KEYS_CHANGED_TXT)) + 4;
  3497.  
  3498.                 if(FastMacrosChanged)
  3499.                     Len += strlen(LocaleString(MSG_WAIT_FAST_MACROS_CHANGED_TXT)) + 4;
  3500.  
  3501.                 if(HotkeysChanged)
  3502.                     Len += strlen(LocaleString(MSG_WAIT_HOTKEYS_CHANGED_TXT)) + 4;
  3503.  
  3504.                 if(SpeechChanged)
  3505.                     Len += strlen(LocaleString(MSG_WAIT_SPEECH_SETTINGS_CHANGED_TXT)) + 4;
  3506.  
  3507.                 if(SoundChanged)
  3508.                     Len += strlen(LocaleString(MSG_WAIT_SOUND_SETTINGS_CHANGED_TXT)) + 4;
  3509.  
  3510.                 BlockWindows();
  3511.  
  3512.                 ChangeWindowPtr(&OldPtr,(APTR)Window);
  3513.  
  3514.                 if(OldLen != Len)
  3515.                 {
  3516.                     if(Buffer = (STRPTR)AllocVecPooled(Len,MEMF_ANY))
  3517.                     {
  3518.                         LimitedSPrintf(Len,Buffer,"%s\n\n",LocaleString(MSG_TERMMAIN_REALLY_QUIT_TXT));
  3519.  
  3520.                         if(Online)
  3521.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_PROGRAM_IS_STILL_ONLINE_TXT));
  3522.  
  3523.                         if(BufferChanged)
  3524.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_REVIEW_BUFFER_NOT_SAVED_TXT));
  3525.  
  3526.                         if(ConfigChanged)
  3527.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_CONFIGURATION_HAS_BEEN_CHANGED_TXT));
  3528.  
  3529.                         if(PhonebookChanged)
  3530.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_PHONEBOOK_NOT_SAVED_TXT));
  3531.  
  3532.                         if(TranslationChanged)
  3533.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_TRANSLATION_TABLES_CHANGED_TXT));
  3534.  
  3535.                         if(MacroChanged)
  3536.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_MACRO_KEYS_CHANGED_TXT));
  3537.  
  3538.                         if(CursorKeysChanged)
  3539.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_CURSOR_KEYS_CHANGED_TXT));
  3540.  
  3541.                         if(FastMacrosChanged)
  3542.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_FAST_MACROS_CHANGED_TXT));
  3543.  
  3544.                         if(HotkeysChanged)
  3545.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_HOTKEYS_CHANGED_TXT));
  3546.  
  3547.                         if(SpeechChanged)
  3548.                             FormatAppend(Buffer," · %s\n",LocaleString(MSG_WAIT_SPEECH_SETTINGS_CHANGED_TXT));
  3549.  
  3550.                         if(ShowRequest(Window,Buffer,LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  3551.                             MainTerminated = TRUE;
  3552.  
  3553.                         FreeVecPooled(Buffer);
  3554.                     }
  3555.                     else
  3556.                         MainTerminated = TRUE;
  3557.                 }
  3558.                 else
  3559.                     MainTerminated = TRUE;
  3560.  
  3561.                 RestoreWindowPtr(OldPtr);
  3562.  
  3563.                 ReleaseWindows();
  3564.             }
  3565.  
  3566.             break;
  3567.  
  3568.             /* Feed the contents of the clipboard
  3569.              * into the input stream.
  3570.              */
  3571.  
  3572.         case MEN_PASTE:
  3573.  
  3574.             if(!OpenClip(Config->ClipConfig->ClipboardUnit))
  3575.             {
  3576.                 ClipInput = TRUE;
  3577.  
  3578.                 if(Qualifier & SHIFT_KEY)
  3579.                     ClipXerox = TRUE;
  3580.             }
  3581.             else
  3582.                 ClipInput = FALSE;
  3583.  
  3584.             break;
  3585.  
  3586.         case MEN_COPY:
  3587.  
  3588.             WindowMarkerTransfer(Qualifier);
  3589.             break;
  3590.  
  3591.         case MEN_CLEAR:
  3592.  
  3593.             WindowMarkerStop();
  3594.             break;
  3595.  
  3596.         case MEN_SELECT_ALL:
  3597.  
  3598.             WindowMarkerSelectAll();
  3599.             break;
  3600.  
  3601.             /* Execute an AmigaDOS command. */
  3602.  
  3603.         case MEN_EXECUTE_DOS_COMMAND:
  3604.  
  3605.             BlockWindows();
  3606.  
  3607.                 /* Enter the name of the command. */
  3608.  
  3609.             if(GetString(TRUE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_AMIGADOS_COMMAND_TXT),AmigaDOSCommandBuffer))
  3610.             {
  3611.                 if(AmigaDOSCommandBuffer[0])
  3612.                     LaunchCommandAsync(AmigaDOSCommandBuffer);
  3613.             }
  3614.  
  3615.             ReleaseWindows();
  3616.  
  3617.             break;
  3618.  
  3619.             /* Execute an ARexx script command. */
  3620.  
  3621.         case MEN_EXECUTE_REXX_COMMAND:
  3622.  
  3623.             BlockWindows();
  3624.  
  3625.                 /* Get the rexx file name/program. */
  3626.  
  3627.             if(GetString(TRUE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_AREXX_COMMAND_TXT),ARexxCommandBuffer))
  3628.             {
  3629.                 if(ARexxCommandBuffer[0])
  3630.                     LaunchRexxAsync(ARexxCommandBuffer);
  3631.             }
  3632.  
  3633.             ReleaseWindows();
  3634.  
  3635.             break;
  3636.  
  3637.             /* Turn recording on/off. */
  3638.  
  3639.         case MEN_RECORD:
  3640.  
  3641.             if(GetItem(MEN_RECORD))
  3642.             {
  3643.                 if(!Recording)
  3644.                 {
  3645.                     if(CreateRecord(CurrentBBSName[0] ? CurrentBBSName : LocaleString(MSG_SCREENPANEL_UNKNOWN_TXT)))
  3646.                     {
  3647.                         RememberResetOutput();
  3648.                         RememberResetInput();
  3649.  
  3650.                         RememberOutput = TRUE;
  3651.  
  3652.                         Recording = TRUE;
  3653.                         RecordingLine = FALSE;
  3654.  
  3655.                         PushStatus(STATUS_RECORDING);
  3656.  
  3657.                         OnItem(MEN_RECORD_LINE);
  3658.                     }
  3659.                 }
  3660.             }
  3661.             else
  3662.             {
  3663.                 if(Recording)
  3664.                 {
  3665.                     FinishRecord();
  3666.  
  3667.                     RememberOutput = FALSE;
  3668.                     RememberInput = FALSE;
  3669.  
  3670.                     Recording = FALSE;
  3671.                     RecordingLine = FALSE;
  3672.  
  3673.                     PopStatus();
  3674.  
  3675.                     OffItem(MEN_RECORD_LINE);
  3676.                 }
  3677.             }
  3678.  
  3679.             break;
  3680.  
  3681.         case MEN_RECORD_LINE:
  3682.  
  3683.             if(Recording)
  3684.             {
  3685.                 if(GetItem(MEN_RECORD))
  3686.                 {
  3687.                     if(!RecordingLine)
  3688.                     {
  3689.                         PopStatus();
  3690.                         PushStatus(STATUS_RECORDING_LINE);
  3691.  
  3692.                         RecordingLine = TRUE;
  3693.  
  3694.                         RememberResetInput();
  3695.  
  3696.                         RememberOutput = FALSE;
  3697.                         RememberInput = TRUE;
  3698.                     }
  3699.                 }
  3700.                 else
  3701.                 {
  3702.                     if(RecordingLine)
  3703.                     {
  3704.                         PopStatus();
  3705.                         PushStatus(STATUS_RECORDING);
  3706.  
  3707.                         RememberSpill();
  3708.  
  3709.                         RecordingLine = FALSE;
  3710.  
  3711.                         RememberOutput = TRUE;
  3712.                         RememberInput = FALSE;
  3713.                     }
  3714.                 }
  3715.             }
  3716.  
  3717.             break;
  3718.  
  3719.         case MEN_DISABLE_TRAPS:
  3720.  
  3721.             Checked = GetItem(MEN_DISABLE_TRAPS);
  3722.  
  3723.             if(Checked || GenericListCount(GenericListTable[GLIST_TRAP]) == 0)
  3724.                 WatchTraps = FALSE;
  3725.             else
  3726.                 WatchTraps = TRUE;
  3727.  
  3728.             break;
  3729.  
  3730.             /* Edit the trap settings? */
  3731.  
  3732.         case MEN_EDIT_TRAPS:
  3733.  
  3734.             BlockWindows();
  3735.  
  3736.             TrapPanelConfig(Config,&TrapsChanged);
  3737.  
  3738.             CheckItem(MEN_DISABLE_TRAPS,!WatchTraps);
  3739.  
  3740.             ReleaseWindows();
  3741.  
  3742.             break;
  3743.  
  3744.             /* Open the phonebook and dial the
  3745.              * list of entries the user will select.
  3746.              */
  3747.  
  3748.         case MEN_PHONEBOOK:
  3749.  
  3750.             BlockWindows();
  3751.  
  3752.             if(PhonePanel(Qualifier))
  3753.             {
  3754.                 if(AskDial(Window))
  3755.                     DoDial = DIAL_LIST;
  3756.             }
  3757.  
  3758.             ReleaseWindows();
  3759.  
  3760.             break;
  3761.  
  3762.             /* Redial those dial list entries which
  3763.              * we were unable to connect.
  3764.              */
  3765.  
  3766.         case MEN_REDIAL:
  3767.  
  3768.             BlockWindows();
  3769.  
  3770.                 /* If the modem is still online, provide help. */
  3771.  
  3772.             if(AskDial(Window))
  3773.                 DoDial = DIAL_LIST;
  3774.  
  3775.             ReleaseWindows();
  3776.  
  3777.             break;
  3778.  
  3779.             /* Dial a single number. */
  3780.  
  3781.         case MEN_DIAL_NUMBER:
  3782.  
  3783.             BlockWindows();
  3784.  
  3785.                 /* If the modem is still online, provide help. */
  3786.  
  3787.             if(AskDial(Window))
  3788.             {
  3789.                 if(GetString(FALSE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_PHONE_NUMBER_TXT),DialNumberBuffer))
  3790.                 {
  3791.                     if(DialNumberBuffer[0])
  3792.                     {
  3793.                             /* Remove all entries from the list. */
  3794.  
  3795.                         DeleteDialList(GlobalPhoneHandle);
  3796.  
  3797.                         if(AddDialEntry(GlobalPhoneHandle,NULL,DialNumberBuffer))
  3798.                             DoDial = DIAL_LIST;
  3799.                     }
  3800.                 }
  3801.             }
  3802.  
  3803.             ReleaseWindows();
  3804.  
  3805.             break;
  3806.  
  3807.             /* Send a break across the serial line. */
  3808.  
  3809.         case MEN_SEND_BREAK:
  3810.  
  3811.             SendBreak();
  3812.             break;
  3813.  
  3814.             /* Hang up the phone line. */
  3815.  
  3816.         case MEN_HANG_UP:
  3817.  
  3818.             FullHangup(FALSE);
  3819.  
  3820.             break;
  3821.  
  3822.             /* Wait a bit... */
  3823.  
  3824.         case MEN_WAIT:
  3825.  
  3826.             Easy.es_StructSize        = sizeof(struct EasyStruct);
  3827.             Easy.es_Flags            = NULL;
  3828.             Easy.es_Title            = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3829.             Easy.es_GadgetFormat    = LocaleString(MSG_GLOBAL_CONTINUE_TXT);
  3830.             Easy.es_TextFormat        = LocaleString(MSG_TERMMAIN_WAITING_TXT);
  3831.  
  3832.             BlockWindows();
  3833.  
  3834.             if(ReqWindow = BuildEasyRequest(Window,&Easy,IDCMP_RAWKEY,NULL))
  3835.             {
  3836.                 ULONG Signals,Mask,Which;
  3837.                 LONG Seconds;
  3838.                 BOOL More;
  3839.  
  3840.                     /* Don't echo serial output. */
  3841.  
  3842.             /*    Quiet = TRUE; */
  3843.  
  3844.                 if(!(Seconds = Config->MiscConfig->WaitDelay))
  3845.                     Seconds = 1;
  3846.  
  3847.                 SerialCommand(Config->MiscConfig->WaitString);
  3848.                 RunJob(SerialJob);
  3849.  
  3850.                 StartTime(Seconds,0);
  3851.  
  3852.                 if(ReadPort && !Get_xOFF() && ProcessIO)
  3853.                     Mask = SIG_SERIAL;
  3854.                 else
  3855.                     Mask = NULL;
  3856.  
  3857.                 More = FALSE;
  3858.  
  3859.                 FOREVER
  3860.                 {
  3861.                     Which = Mask | SIG_REXX | SIG_TIMER | PORTMASK(ReqWindow->UserPort);
  3862.  
  3863.                     if(More)
  3864.                     {
  3865.                         Signals = SetSignal(0,Which) & Which;
  3866.                         More = FALSE;
  3867.                     }
  3868.                     else
  3869.                         Signals = Wait(Which);
  3870.  
  3871.                     if(Signals & PORTMASK(ReqWindow->UserPort))
  3872.                     {
  3873.                         ULONG IDCMP = NULL;
  3874.                         LONG Result;
  3875.  
  3876.                         Result = SysReqHandler(ReqWindow,&IDCMP,FALSE);
  3877.  
  3878.                         if(Result == 0 || (Result == -2 && !(IDCMP & IDCMP_RAWKEY)))
  3879.                         {
  3880.                             StopTime();
  3881.  
  3882.                             SerialCommand(Config->MiscConfig->WaitString);
  3883.  
  3884.                             break;
  3885.                         }
  3886.                     }
  3887.  
  3888.                     if(Signals & SIG_TIMER)
  3889.                     {
  3890.                         WaitTime();
  3891.  
  3892.                         SerialCommand(Config->MiscConfig->WaitString);
  3893.  
  3894.                         StartTime(Seconds,0);
  3895.                     }
  3896.  
  3897.                     if(Signals & Mask)
  3898.                     {
  3899.                         More = RunJob(SerialJob);
  3900.  
  3901.                         if(Get_xOFF())
  3902.                         {
  3903.                             Mask = NULL;
  3904.                             More = FALSE;
  3905.                         }
  3906.                     }
  3907.  
  3908.                     if(Signals & SIG_REXX)
  3909.                     {
  3910.                         struct RexxMsg *Msg;
  3911.  
  3912.                         if(Msg = (struct RexxMsg *)GetMsg(TermRexxPort))
  3913.                         {
  3914.                             Msg->rm_Result1 = RC_ERROR;
  3915.                             Msg->rm_Result2 = ERR10_001;
  3916.  
  3917.                             ReplyMsg((struct Message *)Msg);
  3918.  
  3919.                             More = TRUE;
  3920.                         }
  3921.                     }
  3922.                 }
  3923.  
  3924.                 RunJob(SerialJob);
  3925.  
  3926.             /*    Quiet = FALSE; */
  3927.  
  3928.                 FreeSysRequest(ReqWindow);
  3929.             }
  3930.  
  3931.             ReleaseWindows();
  3932.  
  3933.             break;
  3934.  
  3935.             /* Flush the serial buffers. */
  3936.  
  3937.         case MEN_FLUSH_BUFFER:
  3938.  
  3939.             ClearSerial();
  3940.  
  3941.             RestartSerial();
  3942.  
  3943.             break;
  3944.  
  3945.             /* Release the serial device for other
  3946.              * applications.
  3947.              */
  3948.  
  3949.         case MEN_RELEASE_DEVICE:
  3950.  
  3951.             ActivateJob(MainJobQueue,ReleaseSerialJob);
  3952.             break;
  3953.  
  3954.         case MEN_UPLOAD_ASCII:
  3955.  
  3956.             BlockWindows();
  3957.  
  3958.             if(ChangeProtocol(Config->TransferConfig->ASCIIUploadLibrary,Config->TransferConfig->ASCIIUploadType))
  3959.                 StartSendXPR_AskForFile(TRANSFER_ASCII,TRUE);
  3960.  
  3961.             ResetProtocol();
  3962.  
  3963.             ReleaseWindows();
  3964.  
  3965.             break;
  3966.  
  3967.         case MEN_DOWNLOAD_ASCII:
  3968.  
  3969.             BlockWindows();
  3970.  
  3971.             if(ChangeProtocol(Config->TransferConfig->ASCIIDownloadLibrary,Config->TransferConfig->ASCIIDownloadType))
  3972.                 StartReceiveXPR_AskForFile(TRANSFER_ASCII,TRUE);
  3973.  
  3974.             ResetProtocol();
  3975.  
  3976.             ReleaseWindows();
  3977.  
  3978.             break;
  3979.  
  3980.         case MEN_UPLOAD_TEXT:
  3981.  
  3982.             BlockWindows();
  3983.  
  3984. #ifdef BUILTIN_ZMODEM
  3985.             if(UseInternalZModem)
  3986.             {
  3987.                 InternalZModemTextUpload();
  3988.  
  3989.                 ReleaseWindows();
  3990.                 break;
  3991.             }
  3992. #endif    /* BUILTIN_ZMODEM */
  3993.  
  3994.             if(ChangeProtocol(Config->TransferConfig->TextUploadLibrary,Config->TransferConfig->TextUploadType))
  3995.                 StartSendXPR_AskForFile(TRANSFER_TEXT,TRUE);
  3996.  
  3997.             ResetProtocol();
  3998.  
  3999.             ReleaseWindows();
  4000.  
  4001.             break;
  4002.  
  4003.         case MEN_DOWNLOAD_TEXT:
  4004.  
  4005.             BlockWindows();
  4006.  
  4007. #ifdef BUILTIN_ZMODEM
  4008.             if(UseInternalZModem)
  4009.             {
  4010.                 ZReceive();
  4011.  
  4012.                 ReleaseWindows();
  4013.                 break;
  4014.             }
  4015. #endif    /* BUILTIN_ZMODEM */
  4016.  
  4017.             if(ChangeProtocol(Config->TransferConfig->TextDownloadLibrary,Config->TransferConfig->TextDownloadType))
  4018.                 StartReceiveXPR_AskForFile(TRANSFER_TEXT,TRUE);
  4019.  
  4020.             ResetProtocol();
  4021.  
  4022.             ReleaseWindows();
  4023.  
  4024.             break;
  4025.  
  4026.             /* Edit and transfer a file. */
  4027.  
  4028.         case MEN_EDIT_AND_UPLOAD_TEXT:
  4029.  
  4030.             BlockWindows();
  4031.  
  4032.             if(!Config->PathConfig->Editor[0])
  4033.                 GetString(TRUE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_NAME_OF_EDITOR_TO_USE_TXT),Config->PathConfig->Editor);
  4034.  
  4035.             if(Config->PathConfig->Editor[0])
  4036.             {
  4037.                 DummyBuffer[0] = 0;
  4038.  
  4039.                 if(FileRequest = OpenSingleFile(Window,LocaleString(MSG_TERMMAIN_EDIT_AND_TRANSFER_FILE_TXT),LocaleString(MSG_TERMMAIN_EDIT_TXT),NULL,DummyBuffer,sizeof(DummyBuffer)))
  4040.                 {
  4041.                     UBYTE CompoundName[2 * MAX_FILENAME_LENGTH];
  4042.  
  4043.                     FreeAslRequest(FileRequest);
  4044.  
  4045.                     LimitedStrcpy(sizeof(CompoundName),CompoundName,Config->PathConfig->Editor);
  4046.                     LimitedStrcat(sizeof(CompoundName),CompoundName," \"");
  4047.                     LimitedStrcat(sizeof(CompoundName),CompoundName,DummyBuffer);
  4048.                     LimitedStrcat(sizeof(CompoundName),CompoundName,"\"");
  4049.  
  4050.                     LaunchCommand(CompoundName);
  4051.  
  4052.                     BumpWindow(Window);
  4053.  
  4054.                     if(GetFileSize(DummyBuffer))
  4055.                     {
  4056.                         switch(ShowRequest(Window,LocaleString(MSG_TERMMAIN_TRANSFER_FILE_AS_TXT),LocaleString(MSG_TERMMAIN_ASCII_UPLOAD_CANCEL_TXT),FilePart(DummyBuffer)))
  4057.                         {
  4058.                             case 1:
  4059.  
  4060.                                 if(ChangeProtocol(Config->TransferConfig->ASCIIUploadLibrary,Config->TransferConfig->ASCIIUploadType))
  4061.                                     StartSendXPR_File(TRANSFER_ASCII,DummyBuffer,TRUE);
  4062.  
  4063.                                 ResetProtocol();
  4064.  
  4065.                                 break;
  4066.  
  4067.                             case 2:
  4068.  
  4069.                                 if(ChangeProtocol(Config->TransferConfig->TextUploadLibrary,Config->TransferConfig->TextUploadType))
  4070.                                     StartSendXPR_File(TRANSFER_TEXT,DummyBuffer,TRUE);
  4071.  
  4072.                                 ResetProtocol();
  4073.  
  4074.                                 break;
  4075.                         }
  4076.                     }
  4077.                 }
  4078.             }
  4079.  
  4080.             ReleaseWindows();
  4081.             break;
  4082.  
  4083.         case MEN_UPLOAD_BINARY:
  4084.  
  4085.             BlockWindows();
  4086.  
  4087. #ifdef BUILTIN_ZMODEM
  4088.             if(UseInternalZModem)
  4089.             {
  4090.                 InternalZModemBinaryUpload();
  4091.  
  4092.                 ReleaseWindows();
  4093.                 break;
  4094.             }
  4095. #endif    /* BUILTIN_ZMODEM */
  4096.  
  4097.             if(ChangeProtocol(Config->TransferConfig->BinaryUploadLibrary,Config->TransferConfig->BinaryUploadType))
  4098.                 StartSendXPR_AskForFile(TRANSFER_BINARY,TRUE);
  4099.  
  4100.             ResetProtocol();
  4101.  
  4102.             ReleaseWindows();
  4103.  
  4104.             break;
  4105.  
  4106.             /* Download some files. */
  4107.  
  4108.         case MEN_DOWNLOAD_BINARY:
  4109.  
  4110.             BlockWindows();
  4111.  
  4112. #ifdef BUILTIN_ZMODEM
  4113.             if(UseInternalZModem)
  4114.             {
  4115.                 ZReceive();
  4116.  
  4117.                 ReleaseWindows();
  4118.                 break;
  4119.             }
  4120. #endif    /* BUILTIN_ZMODEM */
  4121.  
  4122.             if(ChangeProtocol(Config->TransferConfig->BinaryDownloadLibrary,Config->TransferConfig->BinaryDownloadType))
  4123.                 StartReceiveXPR_AskForFile(TRANSFER_BINARY,TRUE);
  4124.  
  4125.             ResetProtocol();
  4126.  
  4127.             ReleaseWindows();
  4128.  
  4129.             break;
  4130.  
  4131.             /* Clear the contents of the scrollback
  4132.              * buffer.
  4133.              */
  4134.  
  4135.         case MEN_CLEAR_BUFFER:
  4136.  
  4137.             if(Lines)
  4138.             {
  4139.                 BlockWindows();
  4140.  
  4141.                 if((Qualifier & SHIFT_KEY) || !Config->MiscConfig->ProtectiveMode)
  4142.                 {
  4143.                     FreeBuffer();
  4144.  
  4145.                     TerminateBuffer();
  4146.                 }
  4147.                 else
  4148.                 {
  4149.                     if(ShowRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Lines))
  4150.                     {
  4151.                         FreeBuffer();
  4152.  
  4153.                         TerminateBuffer();
  4154.                     }
  4155.                 }
  4156.  
  4157.                 ReleaseWindows();
  4158.             }
  4159.  
  4160.             break;
  4161.  
  4162.             /* Display the scrollback buffer.
  4163.              * Notify the scrollback task or
  4164.              * fire it off if appropriate.
  4165.              */
  4166.  
  4167.         case MEN_DISPLAY_BUFFER:
  4168.  
  4169.             if(!LaunchBuffer())
  4170.             {
  4171.                 BlockWindows();
  4172.  
  4173.                 ShowRequest(Window,LocaleString(MSG_TERMMAIN_UNABLE_TO_CREATE_BUFFER_TASK_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  4174.  
  4175.                 ReleaseWindows();
  4176.             }
  4177.  
  4178.             break;
  4179.  
  4180.             /* Close the buffer display. */
  4181.  
  4182.         case MEN_CLOSE_BUFFER:
  4183.  
  4184.             TerminateBuffer();
  4185.             break;
  4186.  
  4187.             /* Is the buffer to be frozen? */
  4188.  
  4189.         case MEN_FREEZE_BUFFER:
  4190.  
  4191.             BufferFrozen = GetItem(MEN_FREEZE_BUFFER);
  4192.             ConOutputUpdate();
  4193.  
  4194.             break;
  4195.  
  4196.             /* Load the buffer contents from a file. */
  4197.  
  4198.         case MEN_OPEN_BUFFER:
  4199.  
  4200.             BlockWindows();
  4201.  
  4202.             DummyBuffer[0] = 0;
  4203.  
  4204.             if(FileRequest = OpenSingleFile(Window,LocaleString(MSG_TERMMAIN_LOAD_BUFFER_TXT),LocaleString(MSG_GLOBAL_LOAD_TXT),NULL,DummyBuffer,sizeof(DummyBuffer)))
  4205.             {
  4206.                 FreeAslRequest(FileRequest);
  4207.  
  4208.                 if(GetFileSize(DummyBuffer))
  4209.                 {
  4210.                     if(SomeFile = Open(DummyBuffer,MODE_OLDFILE))
  4211.                     {
  4212.                         if(Lines)
  4213.                         {
  4214.                             switch(ShowRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_TERMMAIN_DISCARD_APPPEND_CANCEL_TXT),Lines))
  4215.                             {
  4216.                                 case 0:
  4217.  
  4218.                                     Close(SomeFile);
  4219.                                     SomeFile = NULL;
  4220.                                     break;
  4221.  
  4222.                                 case 1:
  4223.  
  4224.                                     FreeBuffer();
  4225.                                     break;
  4226.                             }
  4227.                         }
  4228.  
  4229.                         if(SomeFile)
  4230.                         {
  4231.                             LONG Len;
  4232.  
  4233.                             LineRead(NULL,NULL,NULL);
  4234.  
  4235.                             while((Len = LineRead(SomeFile,DummyBuffer,80)) > 0)
  4236.                                 CaptureParser(ParserStuff,DummyBuffer,Len,(COPTR)AddLine);
  4237.  
  4238.                             Close(SomeFile);
  4239.  
  4240.                             BufferChanged = TRUE;
  4241.                         }
  4242.                     }
  4243.                     else
  4244.                         ShowError(Window,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
  4245.                 }
  4246.             }
  4247.  
  4248.             ReleaseWindows();
  4249.             break;
  4250.  
  4251.             /* Save the contents of the scrollback
  4252.              * buffer to a file (line by line).
  4253.              */
  4254.  
  4255.         case MEN_SAVE_BUFFER_AS:
  4256.  
  4257.             BlockWindows();
  4258.  
  4259.             if(!Lines || !BufferLines)
  4260.                 ShowRequest(Window,LocaleString(MSG_GLOBAL_NOTHING_IN_THE_BUFFER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  4261.             else
  4262.             {
  4263.                 DummyBuffer[0] = 0;
  4264.  
  4265.                 if(FileRequest = SaveFile(Window,LocaleString(MSG_TERMMAIN_SAVE_BUFFER_TXT),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  4266.                 {
  4267.                     LONG Error = 0;
  4268.  
  4269.                     FreeAslRequest(FileRequest);
  4270.  
  4271.                     SomeFile = NULL;
  4272.  
  4273.                         /* If the file we are about
  4274.                          * to create already exists,
  4275.                          * ask the user whether we are
  4276.                          * to create, append or skip
  4277.                          * the file.
  4278.                          */
  4279.  
  4280.                     if(GetFileSize(DummyBuffer))
  4281.                     {
  4282.                         switch(ShowRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  4283.                         {
  4284.                             case 1:
  4285.  
  4286.                                 SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  4287.                                 break;
  4288.  
  4289.                             case 2:
  4290.  
  4291.                                 SomeFile = OpenToAppend(DummyBuffer,NULL);
  4292.                                 break;
  4293.                         }
  4294.                     }
  4295.                     else
  4296.                         SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  4297.  
  4298.                     if(SomeFile)
  4299.                     {
  4300.                         LONG i,Len;
  4301.  
  4302.                             /* Obtain the semaphore required
  4303.                              * to gain access to the line buffer
  4304.                              */
  4305.  
  4306.                         SafeObtainSemaphoreShared(&BufferSemaphore);
  4307.  
  4308.                         for(i = 0 ; i < Lines ; i++)
  4309.                         {
  4310.                             Len = BufferLines[i][-1];
  4311.  
  4312.                             if(Len)
  4313.                             {
  4314.                                 SetIoErr(0);
  4315.  
  4316.                                 if(FWrite(SomeFile,BufferLines[i],Len,1) < 1)
  4317.                                 {
  4318.                                     Error = IoErr();
  4319.  
  4320.                                     break;
  4321.                                 }
  4322.                             }
  4323.  
  4324.                             SetIoErr(0);
  4325.  
  4326.                             if(FPrintf(SomeFile,"\n") < 1)
  4327.                             {
  4328.                                 Error = IoErr();
  4329.  
  4330.                                 break;
  4331.                             }
  4332.                         }
  4333.  
  4334.                         ReleaseSemaphore(&BufferSemaphore);
  4335.  
  4336.                         Close(SomeFile);
  4337.  
  4338.                         AddProtection(DummyBuffer,FIBF_EXECUTE);
  4339.  
  4340.                         if(Config->MiscConfig->CreateIcons)
  4341.                             AddIcon(DummyBuffer,FILETYPE_TEXT,TRUE);
  4342.  
  4343.                         BufferChanged = FALSE;
  4344.                     }
  4345.                     else
  4346.                         Error = IoErr();
  4347.  
  4348.                     if(Error)
  4349.                         ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
  4350.                 }
  4351.             }
  4352.  
  4353.             ReleaseWindows();
  4354.  
  4355.             break;
  4356.  
  4357.             /* Simply clear the screen and move the
  4358.              * cursor to its home position.
  4359.              */
  4360.  
  4361.         case MEN_CLEAR_SCREEN:
  4362.  
  4363.             ConClear();
  4364.             break;
  4365.  
  4366.             /* Reset the current text rendering font. */
  4367.  
  4368.         case MEN_RESET_FONT:
  4369.  
  4370.             ConResetFont();
  4371.             break;
  4372.  
  4373.             /* Reset the display styles and restore
  4374.              * the colours.
  4375.              */
  4376.  
  4377.         case MEN_RESET_STYLES:
  4378.  
  4379.             ConResetStyles();
  4380.             break;
  4381.  
  4382.             /* Reset the whole terminal. */
  4383.  
  4384.         case MEN_RESET_TERMINAL:
  4385.  
  4386.             ConResetTerminal();
  4387.             break;
  4388.  
  4389.         case MEN_SET_EMULATION:
  4390.  
  4391.             BlockWindows();
  4392.  
  4393.             if(XEmulatorBase && Config->TerminalConfig->EmulationMode == EMULATION_EXTERNAL)
  4394.             {
  4395.                 OptionTitle = LocaleString(MSG_TERMMAIN_EMULATION_PREFERENCES_TXT);
  4396.  
  4397.                 NewOptions = FALSE;
  4398.  
  4399.                 XEmulatorOptions(XEM_IO);
  4400.  
  4401.                 if(NewOptions)
  4402.                 {
  4403.                     SetEmulatorOptions(XEM_PREFS_SAVE);
  4404.  
  4405.                     NewOptions = FALSE;
  4406.                 }
  4407.  
  4408.                 OptionTitle = NULL;
  4409.             }
  4410.             else
  4411.             {
  4412.                 if(EmulationPanel(Window,Config))
  4413.                 {
  4414.                     ConfigSetup();
  4415.  
  4416.                     ConfigChanged = TRUE;
  4417.                 }
  4418.             }
  4419.  
  4420.             ReleaseWindows();
  4421.  
  4422.             break;
  4423.  
  4424.             /* Set the serial preferences. */
  4425.  
  4426.         case MEN_SERIAL:
  4427.  
  4428.             BlockWindows();
  4429.  
  4430.             if(SerialPanel(Window,Config))
  4431.             {
  4432.                 ConfigSetup();
  4433.  
  4434.                 ConfigChanged = TRUE;
  4435.             }
  4436.  
  4437.             ReleaseWindows();
  4438.  
  4439.             break;
  4440.  
  4441.             /* Set the modem preferences. */
  4442.  
  4443.         case MEN_MODEM:
  4444.  
  4445.             BlockWindows();
  4446.  
  4447.             if(ModemPanel(Window,Config))
  4448.             {
  4449.                 ResetDataFlowFilter();
  4450.  
  4451.                 ConfigChanged = TRUE;
  4452.             }
  4453.  
  4454.             ReleaseWindows();
  4455.  
  4456.             break;
  4457.  
  4458.             /* Set the screen preferences. */
  4459.  
  4460.         case MEN_SCREEN:
  4461.  
  4462.             BlockWindows();
  4463.  
  4464.             if(ScreenPanel(Window,Config))
  4465.             {
  4466.                 if(memcmp(PrivateConfig->ScreenConfig->Colours,Config->ScreenConfig->Colours,sizeof(UWORD) * 16))
  4467.                 {
  4468.                     switch(Config->ScreenConfig->ColourMode)
  4469.                     {
  4470.                         case COLOUR_EIGHT:
  4471.  
  4472.                             CopyMem(Config->ScreenConfig->Colours,ANSIColours,16 * sizeof(UWORD));
  4473.                             break;
  4474.  
  4475.                         case COLOUR_SIXTEEN:
  4476.  
  4477.                             CopyMem(Config->ScreenConfig->Colours,EGAColours,16 * sizeof(UWORD));
  4478.                             break;
  4479.  
  4480.                         case COLOUR_AMIGA:
  4481.  
  4482.                             CopyMem(Config->ScreenConfig->Colours,DefaultColours,16 * sizeof(UWORD));
  4483.                             break;
  4484.  
  4485.                         case COLOUR_MONO:
  4486.  
  4487.                             CopyMem(Config->ScreenConfig->Colours,AtomicColours,16 * sizeof(UWORD));
  4488.                             break;
  4489.                     }
  4490.                 }
  4491.  
  4492.                 ConfigSetup();
  4493.  
  4494.                 ConfigChanged = TRUE;
  4495.             }
  4496.             else
  4497.             {
  4498.                 if(memcmp(PrivateConfig->ScreenConfig->Colours,Config->ScreenConfig->Colours,sizeof(UWORD) * 16))
  4499.                 {
  4500.                     switch(Config->ScreenConfig->ColourMode)
  4501.                     {
  4502.                         case COLOUR_EIGHT:
  4503.  
  4504.                             CopyMem(Config->ScreenConfig->Colours,ANSIColours,16 * sizeof(UWORD));
  4505.                             break;
  4506.  
  4507.                         case COLOUR_SIXTEEN:
  4508.  
  4509.                             CopyMem(Config->ScreenConfig->Colours,EGAColours,16 * sizeof(UWORD));
  4510.                             break;
  4511.  
  4512.                         case COLOUR_AMIGA:
  4513.  
  4514.                             CopyMem(Config->ScreenConfig->Colours,DefaultColours,16 * sizeof(UWORD));
  4515.                             break;
  4516.  
  4517.                         case COLOUR_MONO:
  4518.  
  4519.                             CopyMem(Config->ScreenConfig->Colours,AtomicColours,16 * sizeof(UWORD));
  4520.                             break;
  4521.                     }
  4522.  
  4523.                     ConfigChanged = TRUE;
  4524.                 }
  4525.             }
  4526.  
  4527.             ReleaseWindows();
  4528.  
  4529.             break;
  4530.  
  4531.             /* Set the terminal preferences. */
  4532.  
  4533.         case MEN_TERMINAL:
  4534.  
  4535.             BlockWindows();
  4536.  
  4537.             if(!TerminalPanel(Window,Config))
  4538.                 ReleaseWindows();
  4539.             else
  4540.             {
  4541.                 ReleaseWindows();
  4542.  
  4543.                 Update_CR_LF_Translation();
  4544.  
  4545.                 ConfigSetup();
  4546.  
  4547.                 ConfigChanged = TRUE;
  4548.  
  4549.                     /* Make the changes now */
  4550.  
  4551.                 if(FixScreenSize && !ResetDisplay)
  4552.                 {
  4553.                     ScreenSizeStuff();
  4554.  
  4555.                     ForceStatusUpdate();
  4556.  
  4557.                     HandleMenuCode(MEN_RESET_TERMINAL,0);
  4558.                 }
  4559.             }
  4560.  
  4561.             break;
  4562.  
  4563.             /* Set the clipboard preferences. */
  4564.  
  4565.         case MEN_CLIPBOARD:
  4566.  
  4567.             BlockWindows();
  4568.  
  4569.             if(ClipPanel(Window,Config))
  4570.             {
  4571.                 ConfigSetup();
  4572.  
  4573.                 ConfigChanged = TRUE;
  4574.             }
  4575.  
  4576.             ReleaseWindows();
  4577.  
  4578.             break;
  4579.  
  4580.             /* Set the capture preferences. */
  4581.  
  4582.         case MEN_CAPTURE:
  4583.  
  4584.             BlockWindows();
  4585.  
  4586.             if(CapturePanel(Window,Config))
  4587.             {
  4588.                 ConOutputUpdate();
  4589.  
  4590.                 ConfigSetup();
  4591.  
  4592.                 ConfigChanged = TRUE;
  4593.             }
  4594.  
  4595.             ReleaseWindows();
  4596.  
  4597.             break;
  4598.  
  4599.             /* Set the command preferences. */
  4600.  
  4601.         case MEN_COMMANDS:
  4602.  
  4603.             BlockWindows();
  4604.  
  4605.             if(CommandPanel(Window,Config))
  4606.                 ConfigChanged = TRUE;
  4607.  
  4608.             ReleaseWindows();
  4609.  
  4610.             break;
  4611.  
  4612.             /* Set the miscellaneous preferences. */
  4613.  
  4614.         case MEN_MISC:
  4615.  
  4616.             BlockWindows();
  4617.  
  4618.             if(MiscPanel(Window,Config))
  4619.             {
  4620.                 ConfigSetup();
  4621.  
  4622.                 ConfigChanged = TRUE;
  4623.             }
  4624.  
  4625.             ReleaseWindows();
  4626.  
  4627.             break;
  4628.  
  4629.             /* Set the path settings. */
  4630.  
  4631.         case MEN_PATH:
  4632.  
  4633.             BlockWindows();
  4634.  
  4635.             if(PathPanel(Window,Config))
  4636.                 ConfigChanged = TRUE;
  4637.  
  4638.             ReleaseWindows();
  4639.  
  4640.             break;
  4641.  
  4642.             /* Set the file transfer options. */
  4643.  
  4644.         case MEN_TRANSFER:
  4645.  
  4646.             BlockWindows();
  4647.  
  4648. #ifdef BUILTIN_ZMODEM
  4649.             if(UseInternalZModem)
  4650.             {
  4651.                 ZSettings();
  4652.  
  4653.                 ReleaseWindows();
  4654.  
  4655.                 break;
  4656.             }
  4657. #endif    /* BUILTIN_ZMODEM */
  4658.  
  4659.             XprIO->xpr_filename = NULL;
  4660.  
  4661.                 /* Set up the library options. */
  4662.  
  4663.             if(XProtocolBase)
  4664.             {
  4665.                 XPRCommandSelected = FALSE;
  4666.  
  4667.                 ClearSerial();
  4668.  
  4669.                 NewOptions = FALSE;
  4670.  
  4671.                 TransferBits = XProtocolSetup(XprIO);
  4672.  
  4673.                 RestartSerial();
  4674.  
  4675.                 DeleteTransferPanel(TRUE);
  4676.  
  4677.                     /* Successful? */
  4678.  
  4679.                 if(!(TransferBits & XPRS_SUCCESS))
  4680.                 {
  4681.                     ShowRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_SET_UP_PROTOCOL_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LastXprLibrary);
  4682.  
  4683.                     CloseLibrary(XProtocolBase);
  4684.  
  4685.                     XProtocolBase = NULL;
  4686.  
  4687.                     LastXprLibrary[0] = 0;
  4688.  
  4689.                     TransferBits = 0;
  4690.  
  4691.                     SetTransferMenu(TRUE);
  4692.                 }
  4693.                 else
  4694.                     SaveProtocolOpts();
  4695.             }
  4696.  
  4697.             ReleaseWindows();
  4698.  
  4699.             break;
  4700.  
  4701.             /* Set the file transfer procol settings. */
  4702.  
  4703.         case MEN_TRANSFER_PROTOCOL:
  4704.  
  4705.             BlockWindows();
  4706.  
  4707.             if(LibPanel(Window,Config))
  4708.             {
  4709.                 ConfigSetup();
  4710.  
  4711.                 ConfigChanged = TRUE;
  4712.  
  4713.                 ResetDataFlowFilter();
  4714.             }
  4715.  
  4716.             ReleaseWindows();
  4717.  
  4718.             break;
  4719.  
  4720.             /* Set the translation tables. */
  4721.  
  4722.         case MEN_TRANSLATION:
  4723.  
  4724.             BlockWindows();
  4725.  
  4726.             TranslationPanelConfig(Config,&SendTable,&ReceiveTable,LastTranslation,Window,&TranslationChanged);
  4727.  
  4728.                 /* Choose the right console write routine. */
  4729.  
  4730.             ConOutputUpdate();
  4731.  
  4732.             ReleaseWindows();
  4733.  
  4734.             break;
  4735.  
  4736.             /* Set the keyboard macros. */
  4737.  
  4738.         case MEN_MACROS:
  4739.  
  4740.             BlockWindows();
  4741.  
  4742.             if(XEmulatorBase && Config->TerminalConfig->EmulationMode == EMULATION_EXTERNAL)
  4743.             {
  4744.                 XEmulatorMacroKeyFilter(XEM_IO,NULL);
  4745.  
  4746.                 MacroPanelConfig(Config,MacroKeys,LastMacros,Window,&MacroChanged);
  4747.  
  4748.                 SetupXEM_MacroKeys(MacroKeys);
  4749.             }
  4750.             else
  4751.                 MacroPanelConfig(Config,MacroKeys,LastMacros,Window,&MacroChanged);
  4752.  
  4753.             ReleaseWindows();
  4754.  
  4755.             break;
  4756.  
  4757.             /* Set the cursor keys. */
  4758.  
  4759.         case MEN_CURSORKEYS:
  4760.  
  4761.             BlockWindows();
  4762.  
  4763.             CursorPanelConfig(Config,CursorKeys,LastCursorKeys,Window,&CursorKeysChanged);
  4764.  
  4765.             ReleaseWindows();
  4766.  
  4767.             break;
  4768.  
  4769.             /* Set the fast macros. */
  4770.  
  4771.         case MEN_FAST_MACROS:
  4772.  
  4773.             BlockWindows();
  4774.  
  4775.             if(FastMacroPanelConfig(Config,&FastMacroList,LastFastMacros,Window,&FastMacrosChanged))
  4776.             {
  4777.                 FastMacroCount = GetListSize(&FastMacroList);
  4778.                 RefreshFastWindow();
  4779.             }
  4780.  
  4781.             ReleaseWindows();
  4782.  
  4783.             break;
  4784.  
  4785.             /* Set the hotkey preferences. */
  4786.  
  4787.         case MEN_HOTKEYS:
  4788.  
  4789.             BlockWindows();
  4790.  
  4791.             if(HotkeyPanelConfig(Config,&Hotkeys,LastKeys,&HotkeysChanged))
  4792.             {
  4793.                 if(LastKeys[0] && !SetupCx())
  4794.                     ShowRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_SET_UP_HOTKEYS_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  4795.             }
  4796.  
  4797.             ReleaseWindows();
  4798.  
  4799.             break;
  4800.  
  4801.             /* Set the speech preferences. */
  4802.  
  4803.         case MEN_SPEECH:
  4804.  
  4805.             BlockWindows();
  4806.  
  4807.             SpeechPanelConfig(&SpeechConfig,LastSpeech,&SpeechChanged);
  4808.  
  4809.             ReleaseWindows();
  4810.  
  4811.             break;
  4812.  
  4813.             /* Set the sound preferences. */
  4814.  
  4815.         case MEN_SOUND:
  4816.  
  4817.             BlockWindows();
  4818.  
  4819.             if(SoundPanelConfig(&SoundConfig,LastSound,&SoundChanged))
  4820.             {
  4821.                 if(LastSound[0])
  4822.                     SoundInit();
  4823.             }
  4824.  
  4825.             ReleaseWindows();
  4826.  
  4827.             break;
  4828.  
  4829.             /* Edit the phone number patterns and rates. */
  4830.  
  4831.         case MEN_RATES:
  4832.  
  4833.             BlockWindows();
  4834.  
  4835.             PatternPanelConfig(PatternList,LastPattern,&PatternsChanged);
  4836.  
  4837.             ReleaseWindows();
  4838.  
  4839.             break;
  4840.  
  4841.             /* Open the preferences settings. */
  4842.  
  4843.         case MEN_OPEN_SETTINGS:
  4844.  
  4845.             BlockWindows();
  4846.  
  4847.             strcpy(DummyBuffer,LastConfig);
  4848.  
  4849.             if(FileRequest = OpenSingleFile(Window,LocaleString(MSG_TERMMAIN_OPEN_PREFERENCES_TXT),NULL,"#?.prefs",DummyBuffer,sizeof(DummyBuffer)))
  4850.             {
  4851.                 FreeAslRequest(FileRequest);
  4852.  
  4853.                 if(ReadConfig(DummyBuffer,PrivateConfig))
  4854.                 {
  4855.                     SwapConfig(PrivateConfig,Config);
  4856.  
  4857.                     strcpy(LastConfig,DummyBuffer);
  4858.  
  4859.                     ConfigSetup();
  4860.  
  4861.                     ConfigChanged = FALSE;
  4862.                 }
  4863.                 else
  4864.                     ShowRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  4865.             }
  4866.  
  4867.             ReleaseWindows();
  4868.  
  4869.             break;
  4870.  
  4871.             /* Save the terminal preferences. */
  4872.  
  4873.         case MEN_SAVE_SETTINGS:
  4874.  
  4875.             if(LastConfig[0])
  4876.             {
  4877.                 BlockWindows();
  4878.  
  4879.                 if(!Screen)
  4880.                     PutWindowInfo(WINDOW_MAIN,Window->LeftEdge,Window->TopEdge,Window->Width,Window->Height);
  4881.  
  4882.                 if(!WriteConfig(LastConfig,Config))
  4883.                     ShowError(Window,ERR_SAVE_ERROR,IoErr(),LastConfig);
  4884.                 else
  4885.                     ConfigChanged = FALSE;
  4886.  
  4887.                 ReleaseWindows();
  4888.  
  4889.                 break;
  4890.             }
  4891.  
  4892.             /* Save the terminal preferences to a
  4893.              * given file name.
  4894.              */
  4895.  
  4896.         case MEN_SAVE_SETTINGS_AS:
  4897.  
  4898.             BlockWindows();
  4899.  
  4900.             strcpy(DummyBuffer,LastConfig);
  4901.  
  4902.             if(FileRequest = SaveFile(Window,LocaleString(MSG_TERMMAIN_SAVE_PREFERENCES_AS_TXT),NULL,"#?.prefs",DummyBuffer,sizeof(DummyBuffer)))
  4903.             {
  4904.                 FreeAslRequest(FileRequest);
  4905.  
  4906.                 if(!Screen)
  4907.                     PutWindowInfo(WINDOW_MAIN,Window->LeftEdge,Window->TopEdge,Window->Width,Window->Height);
  4908.  
  4909.                 if(WriteConfig(DummyBuffer,Config))
  4910.                 {
  4911.                     strcpy(LastConfig,DummyBuffer);
  4912.  
  4913.                     ConfigChanged = FALSE;
  4914.                 }
  4915.                 else
  4916.                     ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
  4917.             }
  4918.  
  4919.             ReleaseWindows();
  4920.  
  4921.             break;
  4922.  
  4923.             /* Show terminal information window. */
  4924.  
  4925.         case MEN_STATUS_WINDOW:
  4926.  
  4927.             if(InfoWindow)
  4928.                 CloseInfoWindow();
  4929.             else
  4930.                 OpenInfoWindow();
  4931.  
  4932.             break;
  4933.  
  4934.         case MEN_REVIEW_WINDOW:
  4935.  
  4936.             if(ReviewWindow)
  4937.                 DeleteReview();
  4938.             else
  4939.                 CreateReview();
  4940.  
  4941.             break;
  4942.  
  4943.         case MEN_MATRIX_WINDOW:
  4944.  
  4945.             if(MatrixWindow)
  4946.                 CloseMatrixWindow();
  4947.             else
  4948.                 OpenMatrixWindow(Window);
  4949.  
  4950.             break;
  4951.  
  4952.             /* Open the packet window if necessary, else
  4953.              * just activate it.
  4954.              */
  4955.  
  4956.         case MEN_PACKET_WINDOW:
  4957.  
  4958.             CreatePacketWindow();
  4959.             break;
  4960.  
  4961.             /* Enable or disable the packet window */
  4962.  
  4963.         case MEN_CHAT_LINE:
  4964.  
  4965.             Checked = GetItem(MEN_CHAT_LINE);
  4966.  
  4967.             if(Checked != ChatMode)
  4968.             {
  4969.                 ChatMode = Checked;
  4970.  
  4971.                 ResetDisplay = TRUE;
  4972.                 ActivateJob(MainJobQueue,ResetDisplayJob);
  4973.             }
  4974.  
  4975.             break;
  4976.  
  4977.             /* Toggle the presence of the fast! macro panel. */
  4978.  
  4979.         case MEN_FAST_MACROS_WINDOW:
  4980.  
  4981.             if(FastWindow)
  4982.                 CloseFastWindow();
  4983.             else
  4984.                 OpenFastWindow();
  4985.  
  4986.             break;
  4987.  
  4988.             /* Open the upload queue window. */
  4989.  
  4990.         case MEN_UPLOAD_QUEUE_WINDOW:
  4991.  
  4992.             CreateQueueProcess();
  4993.             break;
  4994.  
  4995.             /* Check if we should go for the quick dial menu */
  4996.  
  4997.         default:
  4998.  
  4999.             if(Code >= DIAL_MENU_LIMIT)
  5000.                 CheckDialMenu = TRUE;
  5001.  
  5002.             break;
  5003.     }
  5004. }
  5005.  
  5006.     /* HandleReleaseSerial():
  5007.      *
  5008.      *    Release the serial device driver, then reopen it again.
  5009.      */
  5010.  
  5011. BOOL
  5012. HandleReleaseSerial(JobNode *UnusedJob)
  5013. {
  5014.     if(!MainTerminated)
  5015.         LocalReleaseSerial();
  5016.  
  5017.     return(FALSE);
  5018. }
  5019.  
  5020.     /* HandleStartupFile(JobNode *Job):
  5021.      *
  5022.      *    Launches the startup ARexx script.
  5023.      */
  5024.  
  5025. BOOL
  5026. HandleStartupFile(JobNode *UnusedJob)
  5027. {
  5028.     if(!MainTerminated)
  5029.     {
  5030.         LaunchRexxAsync(StartupFile);
  5031.  
  5032.         StartupFile[0] = 0;
  5033.     }
  5034.  
  5035.     return(FALSE);
  5036. }
  5037.  
  5038. BOOL
  5039. HandleIconifyJob(JobNode *UnusedJob)
  5040. {
  5041.     if(!MainTerminated)
  5042.         HandleIconify();
  5043.  
  5044.     return(FALSE);
  5045. }
  5046.  
  5047. BOOL
  5048. HandleRebuildMenuJob(JobNode *UnusedJob)
  5049. {
  5050.     if(!ResetDisplay && !MainTerminated)
  5051.     {
  5052.         struct Menu *Menu;
  5053.  
  5054.         if(Menu = BuildMenu())
  5055.             AttachMenu(Menu);
  5056.         else
  5057.             DisconnectDialMenu();
  5058.  
  5059.         RebuildMenu = FALSE;
  5060.     }
  5061.  
  5062.     return(FALSE);
  5063. }
  5064.  
  5065. BOOL
  5066. HandleResetDisplayJob(JobNode *UnusedJob)
  5067. {
  5068.     if(!MainTerminated)
  5069.     {
  5070.         if(!DisplayReset())
  5071.             MainTerminated = TRUE;
  5072.     }
  5073.  
  5074.     return(FALSE);
  5075. }
  5076.  
  5077. BOOL
  5078. HandleOnlineCleanupJob(JobNode *UnusedJob)
  5079. {
  5080.     if(!MainTerminated)
  5081.     {
  5082.         HandleOnlineCleanup(HungUp);
  5083.  
  5084.         WasOnline    = FALSE;
  5085.         HungUp        = FALSE;
  5086.     }
  5087.  
  5088.     return(FALSE);
  5089. }
  5090.  
  5091. BOOL
  5092. HandleDisplayCostJob(JobNode *Job)
  5093. {
  5094.     BOOL TurnOff = TRUE;
  5095.  
  5096.     if(!MainTerminated)
  5097.     {
  5098.         if(ResetDisplay)
  5099.             TurnOff = FALSE;
  5100.         else
  5101.         {
  5102.             UBYTE Sum[20];
  5103.             LONG ID;
  5104.  
  5105.                 /* Reset the text rendering styles, font, etc. in
  5106.                  * order to keep the following text from getting
  5107.                  * illegible.
  5108.                  */
  5109.  
  5110.             SoftReset();
  5111.  
  5112.             if(DisplayPay)
  5113.             {
  5114.                 if(DisplayHangup)
  5115.                     ID = MSG_TERMMAIN_LOGMSG_HANG_UP_COST_TXT;
  5116.                 else
  5117.                     ID = MSG_TERMAUX_CARRIER_LOST_COST_TXT;
  5118.  
  5119.                 CreateSum((DisplayPay + 5000) / 10000,TRUE,Sum,sizeof(Sum));
  5120.  
  5121.                     /* Display how much we expect
  5122.                      * the user will have to pay for
  5123.                      * this call.
  5124.                      */
  5125.  
  5126.                 ConPrintf(LocaleString(MSG_TERMMAIN_THIS_CALL_WILL_COST_YOU_TXT),Sum);
  5127.             }
  5128.             else
  5129.             {
  5130.                 if(DisplayHangup)
  5131.                     ID = MSG_TERMMAIN_LOGMSG_HANG_UP_TXT;
  5132.                 else
  5133.                     ID = MSG_TERMAUX_CARRIER_LOST_TXT;
  5134.  
  5135.                 Sum[0] = 0;
  5136.             }
  5137.  
  5138.             LogAction(LocaleString(ID),Sum);
  5139.  
  5140.             DisplayHangup    = FALSE;
  5141.             DisplayPay        = 0;
  5142.         }
  5143.     }
  5144.  
  5145.     if(TurnOff)
  5146.         SuspendJob(MainJobQueue,Job);
  5147.  
  5148.     return(FALSE);
  5149. }
  5150.